| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___MEMORY_ADDRESSOF_H |
| 11 | #define _LIBCPP___MEMORY_ADDRESSOF_H |
| 12 | |
| 13 | #include <__config> |
| 14 | |
| 15 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 16 | # pragma GCC system_header |
| 17 | #endif |
| 18 | |
| 19 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 20 | |
| 21 | template <class _Tp> |
| 22 | [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* |
| 23 | addressof(_Tp& __x) _NOEXCEPT { |
| 24 | return __builtin_addressof(__x); |
| 25 | } |
| 26 | |
| 27 | #if __has_feature(objc_arc) |
| 28 | // Objective-C++ Automatic Reference Counting uses qualified pointers |
| 29 | // that require special addressof() signatures. |
| 30 | template <class _Tp> |
| 31 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT { |
| 32 | return &__x; |
| 33 | } |
| 34 | |
| 35 | # if __has_feature(objc_arc_weak) |
| 36 | template <class _Tp> |
| 37 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT { |
| 38 | return &__x; |
| 39 | } |
| 40 | # endif |
| 41 | |
| 42 | template <class _Tp> |
| 43 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __autoreleasing _Tp* addressof(__autoreleasing _Tp& __x) _NOEXCEPT { |
| 44 | return &__x; |
| 45 | } |
| 46 | |
| 47 | template <class _Tp> |
| 48 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __unsafe_unretained _Tp* |
| 49 | addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT { |
| 50 | return &__x; |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | #if !defined(_LIBCPP_CXX03_LANG) |
| 55 | template <class _Tp> |
| 56 | _Tp* addressof(const _Tp&&) noexcept = delete; |
| 57 | #endif |
| 58 | |
| 59 | _LIBCPP_END_NAMESPACE_STD |
| 60 | |
| 61 | #endif // _LIBCPP___MEMORY_ADDRESSOF_H |
| 62 | |