cast: account for pointers-to-const in ffs
This commit is contained in:
parent
82b0bb2245
commit
75d5f84ff6
12
cast.hpp
12
cast.hpp
@ -188,7 +188,17 @@ namespace cruft::cast {
|
||||
#if defined(COMPILER_GCC)
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||
#endif
|
||||
return reinterpret_cast<DstT> (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<SrcT>) {
|
||||
using value_type = std::remove_pointer_t<SrcT>;
|
||||
return reinterpret_cast<DstT> (
|
||||
const_cast<std::remove_cv_t<value_type>*> (src)
|
||||
);
|
||||
} else {
|
||||
return reinterpret_cast<DstT> (src);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user