diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-06-22 22:17:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-06-22 22:17:44 +0000 |
commit | 64ec101eb6a5d21bcb7bedc334b793c45cd15466 (patch) | |
tree | 7b2ef164b237dbe3a29312a1f23258f9e426cdfc /libcxx | |
parent | 46d1ce23a787d51cd231e45ff0630f9b82685d72 (diff) | |
download | bcm5719-llvm-64ec101eb6a5d21bcb7bedc334b793c45cd15466.tar.gz bcm5719-llvm-64ec101eb6a5d21bcb7bedc334b793c45cd15466.zip |
Teach libc++ about the addressof() overloads it needs to work with
Objective-C Automatic Reference Counting, where Objective-C object
pointers can have several different qualifiers (__strong, __weak,
__autoreleasing, __unsafe_unretained). These addressof() overloads are
only provided in ARC mode, and the __weak variant is conditionalized
on having weak-reference support in the ARC runtime.
For historical reasons, Clang provides these definitions itself, and
defines the macro _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF to note when
it as done so. The code belongs here, and this redundancy will be
eliminated in the future.
Addresses <rdar://problem/9658274>.
llvm-svn: 133656
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/__config | 9 | ||||
-rw-r--r-- | libcxx/include/memory | 40 |
2 files changed, 49 insertions, 0 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config index fea7a96bc86..a943274919e 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -157,6 +157,15 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_TRAILING_RETURN #endif +// Objective-C++ features (opt-in) +#if __has_feature(objc_arc) +#define _LIBCPP_HAS_OBJC_ARC +#endif + +#if __has_feature(objc_arc_weak) +#define _LIBCPP_HAS_OBJC_ARC_WEAK +#endif + // Inline namespaces are available in Clang regardless of C++ dialect. #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE { #define _LIBCPP_END_NAMESPACE_STD } } diff --git a/libcxx/include/memory b/libcxx/include/memory index 6f6a8ce3f7a..479077fb977 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -619,6 +619,46 @@ addressof(_Tp& __x) _NOEXCEPT return (_Tp*)&(char&)__x; } +#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler +// itself is providing these definitions. Otherwise, we provide them. +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + template <class _Tp> class allocator; template <> |