Skip to content

Commit

Permalink
Replace reinterpret_cast with static_cast.
Browse files Browse the repository at this point in the history
Conversion between pointers of unrelated types `Source` and `Target`
can be done with `static_cast` => IMO should be done with `static_cast`
(in order not to give the impression that `reinterpret_cast` really is needed):

  `T *ptr_target = static_cast <T *> (static_cast <void *> (ptr_source));`

IMO `reinterpret_cast` should be used for pointer-to-integral and integral-to-pointer
conversions (only).
  • Loading branch information
Adder committed Jun 13, 2023
1 parent 1ebd31e commit 510eec1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/boost/type_traits/integral_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace boost{
{
static const char data[sizeof(long)] = { 0 };
static const void* pdata = data;
return *(reinterpret_cast<const mpl::integral_c<T, val>*>(pdata));
return *static_cast<const mpl::integral_c<T, val>*>(pdata);
}
BOOST_CONSTEXPR operator T()const { return val; }
};
Expand All @@ -81,7 +81,7 @@ namespace boost{
{
static const char data[sizeof(long)] = { 0 };
static const void* pdata = data;
return *(reinterpret_cast<const mpl::bool_<val>*>(pdata));
return *static_cast<const mpl::bool_<val>*>(pdata);
}
BOOST_CONSTEXPR operator bool()const { return val; }
};
Expand Down

0 comments on commit 510eec1

Please sign in to comment.