From 0422aebeb80deac7a69757faf121f35b9beba5cd Mon Sep 17 00:00:00 2001 From: Adder Date: Tue, 13 Jun 2023 23:29:56 +0300 Subject: [PATCH] `integral_constant`: MPL interop: Avoid `reinterpret_cast`. Conversion between pointers to unrelated types `Source` and `Target` can be done with two `static_cast`'s ("upcast" to pointer to cv-void followed by "downcast") => (IMO) it should be done with `static_cast` (in order not to give the impression that `reinterpret_cast` really is needed): `T *ptr_target = static_cast (static_cast (ptr_source));` (Maybe that was the original intent of introducing `pdata`.) --- include/boost/type_traits/integral_constant.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/type_traits/integral_constant.hpp b/include/boost/type_traits/integral_constant.hpp index 2592bcb..47699be 100644 --- a/include/boost/type_traits/integral_constant.hpp +++ b/include/boost/type_traits/integral_constant.hpp @@ -61,7 +61,7 @@ namespace boost{ { static const char data[sizeof(long)] = { 0 }; static const void* pdata = data; - return *(reinterpret_cast*>(pdata)); + return *static_cast*>(pdata); } BOOST_CONSTEXPR operator T()const { return val; } }; @@ -81,7 +81,7 @@ namespace boost{ { static const char data[sizeof(long)] = { 0 }; static const void* pdata = data; - return *(reinterpret_cast*>(pdata)); + return *static_cast*>(pdata); } BOOST_CONSTEXPR operator bool()const { return val; } };