summaryrefslogtreecommitdiff
path: root/boost/dll/detail/aggressive_ptr_cast.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/dll/detail/aggressive_ptr_cast.hpp')
-rw-r--r--boost/dll/detail/aggressive_ptr_cast.hpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/boost/dll/detail/aggressive_ptr_cast.hpp b/boost/dll/detail/aggressive_ptr_cast.hpp
index a882cd9b19..8d1ecc112b 100644
--- a/boost/dll/detail/aggressive_ptr_cast.hpp
+++ b/boost/dll/detail/aggressive_ptr_cast.hpp
@@ -1,5 +1,5 @@
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
-// Copyright 2015-2016 Antony Polukhin.
+// Copyright 2015-2017 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
@@ -21,9 +21,12 @@
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>
-#include <boost/cstdint.hpp> // boost::uintptr_t
#include <cstring> // std::memcpy
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
+# pragma GCC system_header
+#endif
+
namespace boost { namespace dll { namespace detail {
// GCC warns when reinterpret_cast between function pointer and object pointer occur.
@@ -48,11 +51,14 @@ BOOST_FORCEINLINE typename boost::disable_if_c<boost::is_member_pointer<To>::val
"Pointer to function and pointer to object differ in size on your platform."
);
- return reinterpret_cast<To>(
- reinterpret_cast<boost::uintptr_t>(v)
- );
+ return reinterpret_cast<To>(v);
}
+#ifdef BOOST_MSVC
+# pragma warning(push)
+# pragma warning(disable: 4172) // "returning address of local variable or temporary" but **v is not local!
+#endif
+
template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_reference<To>::value || boost::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From v) BOOST_NOEXCEPT
@@ -71,18 +77,17 @@ BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_reference<To>::value |
sizeof(v) == sizeof(typename boost::remove_reference<To>::type*),
"Pointer to function and pointer to object differ in size on your platform."
);
-
return static_cast<To>(
- *reinterpret_cast<typename boost::remove_reference<To>::type*>(
- *reinterpret_cast<boost::uintptr_t*>(
- reinterpret_cast<unsigned char*>(
- v
- )
- )
+ **reinterpret_cast<typename boost::remove_reference<To>::type**>(
+ v
)
);
}
+#ifdef BOOST_MSVC
+# pragma warning(pop)
+#endif
+
template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_member_pointer<To>::value || boost::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From v) BOOST_NOEXCEPT
@@ -98,7 +103,7 @@ BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_member_pointer<To>::va
);
To res = 0;
- std::memcpy(&res, &v, sizeof(To));
+ std::memcpy(&res, &v, sizeof(From));
return res;
}