[libcxx-commits] [PATCH] D60087: [libc++] Correctly handle Objective-C++ ARC qualifiers in std::is_pointer

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 1 12:00:45 PDT 2019


ldionne created this revision.
ldionne added a reviewer: ahatanak.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous, christof.

Otherwise, std::is_pointer<id __strong> works, but std::is_pointer<id __weak>
(and others) don't work as expected.

rdar://problem/49126333


Repository:
  rCXX libc++

https://reviews.llvm.org/D60087

Files:
  libcxx/include/type_traits
  libcxx/test/libcxx/type_traits/is_pointer_objc.arc.pass.mm


Index: libcxx/test/libcxx/type_traits/is_pointer_objc.arc.pass.mm
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/type_traits/is_pointer_objc.arc.pass.mm
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++98, c++03
+
+// <type_traits>
+
+// std::is_pointer
+
+// Test that we correctly handle Objective-C++ ARC qualifiers on pointers.
+
+#include <type_traits>
+
+
+static_assert(std::is_pointer<__weak id>::value, "");
+static_assert(std::is_pointer<__strong id>::value, "");
+static_assert(std::is_pointer<__autoreleasing id>::value, "");
+static_assert(std::is_pointer<__unsafe_unretained id>::value, "");
+
+int main(int, char**) {
+    return 0;
+}
Index: libcxx/include/type_traits
===================================================================
--- libcxx/include/type_traits
+++ libcxx/include/type_traits
@@ -784,6 +784,11 @@
 
 template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
 template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
+#if defined(_LIBCPP_HAS_OBJC_ARC)
+template <class _Tp> struct __libcpp_is_pointer<_Tp* __weak> : public true_type {};
+template <class _Tp> struct __libcpp_is_pointer<_Tp* __autoreleasing> : public true_type {};
+template <class _Tp> struct __libcpp_is_pointer<_Tp* __unsafe_unretained> : public true_type {};
+#endif
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
     : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60087.193146.patch
Type: text/x-patch
Size: 1873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190401/011136d9/attachment.bin>


More information about the libcxx-commits mailing list