Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:43:43

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * Copyright (c) 2018 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/addressof.hpp
0010  *
0011  * This header defines \c addressof helper function. It is similar to \c boost::addressof but it is more
0012  * lightweight and also contains a workaround for some compiler warnings.
0013  */
0014 
0015 #ifndef BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_
0016 #define BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_
0017 
0018 #include <boost/atomic/detail/config.hpp>
0019 #include <boost/atomic/detail/header.hpp>
0020 
0021 #ifdef BOOST_HAS_PRAGMA_ONCE
0022 #pragma once
0023 #endif
0024 
0025 // Detection logic is based on boost/core/addressof.hpp
0026 #if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
0027 #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
0028 #elif defined(BOOST_GCC) && BOOST_GCC >= 70000
0029 #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
0030 #elif defined(__has_builtin)
0031 #if __has_builtin(__builtin_addressof)
0032 #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
0033 #endif
0034 #endif
0035 
0036 namespace boost {
0037 namespace atomics {
0038 namespace detail {
0039 
0040 template< typename T >
0041 BOOST_FORCEINLINE
0042 #if defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF)
0043 BOOST_CONSTEXPR
0044 #endif
0045 T* addressof(T& value) BOOST_NOEXCEPT
0046 {
0047 #if defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF)
0048     return __builtin_addressof(value);
0049 #else
0050     // Note: The point of using a local struct as the intermediate type instead of char is to avoid gcc warnings
0051     // if T is a const volatile char*:
0052     // warning: casting 'const volatile char* const' to 'const volatile char&' does not dereference pointer
0053     // The local struct makes sure T is not related to the cast target type.
0054     struct opaque_type;
0055     return reinterpret_cast< T* >(&const_cast< opaque_type& >(reinterpret_cast< const volatile opaque_type& >(value)));
0056 #endif
0057 }
0058 
0059 } // namespace detail
0060 } // namespace atomics
0061 } // namespace boost
0062 
0063 #include <boost/atomic/detail/footer.hpp>
0064 
0065 #endif // BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_