1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015-2019 Antony Polukhin.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP
9 #define BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP
11 #include <boost/config.hpp>
12 #ifdef BOOST_HAS_PRAGMA_ONCE
16 #include <boost/static_assert.hpp>
17 #include <boost/type_traits/is_pointer.hpp>
19 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
20 # pragma GCC system_header
23 namespace boost { namespace stacktrace { namespace detail {
25 // GCC warns when reinterpret_cast between function pointer and object pointer occur.
26 // This functionsuppress the warnings and ensures that such casts are safe.
27 template <class To, class From>
28 To void_ptr_cast(From* v) BOOST_NOEXCEPT {
29 BOOST_STATIC_ASSERT_MSG(
30 boost::is_pointer<To>::value,
31 "`void_ptr_cast` function must be used only for casting to or from void pointers."
34 BOOST_STATIC_ASSERT_MSG(
35 sizeof(From*) == sizeof(To),
36 "Pointer to function and pointer to object differ in size on your platform."
39 return reinterpret_cast<To>(v);
43 }}} // boost::stacktrace::detail
45 #endif // BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP