diff --git a/cast.hpp b/cast.hpp index d46c4535..7dfd20c3 100644 --- a/cast.hpp +++ b/cast.hpp @@ -188,7 +188,17 @@ namespace cruft::cast { #if defined(COMPILER_GCC) #pragma GCC diagnostic ignored "-Wcast-function-type" #endif - return reinterpret_cast (src); + // If we're casting a pointer then we may need to first use a + // const_cast if we want to avoid any warnings about casting, eg in + // the case of `const ValueT*` to `ValueT*` + if constexpr (std::is_pointer_v) { + using value_type = std::remove_pointer_t; + return reinterpret_cast ( + const_cast*> (src) + ); + } else { + return reinterpret_cast (src); + } #pragma GCC diagnostic pop }