]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/stacktrace/detail/void_ptr_cast.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / stacktrace / detail / void_ptr_cast.hpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015-2019 Antony Polukhin.
3 //
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)
7
8 #ifndef BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP
9 #define BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP
10
11 #include <boost/config.hpp>
12 #ifdef BOOST_HAS_PRAGMA_ONCE
13 # pragma once
14 #endif
15
16 #include <boost/static_assert.hpp>
17 #include <boost/type_traits/is_pointer.hpp>
18
19 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
20 # pragma GCC system_header
21 #endif
22
23 namespace boost { namespace stacktrace { namespace detail {
24
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."
32 );
33
34 BOOST_STATIC_ASSERT_MSG(
35 sizeof(From*) == sizeof(To),
36 "Pointer to function and pointer to object differ in size on your platform."
37 );
38
39 return reinterpret_cast<To>(v);
40 }
41
42
43 }}} // boost::stacktrace::detail
44
45 #endif // BOOST_STACKTRACE_DETAIL_VOID_PTR_CAST_HPP
46