summaryrefslogtreecommitdiff
path: root/boost/atomic/detail/bitwise_cast.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/atomic/detail/bitwise_cast.hpp')
-rw-r--r--boost/atomic/detail/bitwise_cast.hpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/boost/atomic/detail/bitwise_cast.hpp b/boost/atomic/detail/bitwise_cast.hpp
index 8654d10b95..1405a25d6a 100644
--- a/boost/atomic/detail/bitwise_cast.hpp
+++ b/boost/atomic/detail/bitwise_cast.hpp
@@ -29,6 +29,17 @@ namespace boost {
namespace atomics {
namespace detail {
+template< typename T >
+BOOST_FORCEINLINE T* addressof(T& value) BOOST_NOEXCEPT
+{
+ // Note: The point of using a local struct as the intermediate type instead of char is to avoid gcc warnings
+ // if T is a const volatile char*:
+ // warning: casting ‘const volatile char* const’ to ‘const volatile char&’ does not dereference pointer
+ // The local struct makes sure T is not related to the cast target type.
+ struct opaque_type;
+ return reinterpret_cast< T* >(&const_cast< opaque_type& >(reinterpret_cast< const volatile opaque_type& >(value)));
+}
+
template< typename To, typename From >
BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT
{
@@ -39,8 +50,8 @@ BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT
value = {};
BOOST_ATOMIC_DETAIL_MEMCPY
(
- &reinterpret_cast< char& >(value.to),
- &reinterpret_cast< const char& >(from),
+ atomics::detail::addressof(value.to),
+ atomics::detail::addressof(from),
(sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To))
);
return value.to;