[libcxx] r221395 - Fix operator & detection trait to check for free function overloads as well

Eric Fiselier eric at efcs.ca
Wed Nov 5 12:59:18 PST 2014


Author: ericwf
Date: Wed Nov  5 14:59:18 2014
New Revision: 221395

URL: http://llvm.org/viewvc/llvm-project?rev=221395&view=rev
Log:
Fix operator & detection trait to check for free function overloads as well

Modified:
    libcxx/trunk/include/type_traits
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=221395&r1=221394&r2=221395&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Nov  5 14:59:18 2014
@@ -3642,7 +3642,7 @@ struct underlying_type
 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
 
 template <class _Tp>
-struct __has_operator_addressof_imp
+struct __has_operator_addressof_member_imp
 {
     template <class>
         static auto __test(__any) -> false_type;
@@ -3654,8 +3654,21 @@ struct __has_operator_addressof_imp
 };
 
 template <class _Tp>
+struct __has_operator_addressof_free_imp
+{
+    template <class>
+        static auto __test(__any) -> false_type;
+    template <class _Up>
+        static auto __test(_Up* __u)
+            -> typename __select_2nd<decltype(operator&(*__u)), true_type>::type;
+
+    static const bool value = decltype(__test<_Tp>(nullptr))::value;
+};
+
+template <class _Tp>
 struct __has_operator_addressof
-    : public integral_constant<bool, __has_operator_addressof_imp<_Tp>::value>
+    : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
+                                  || __has_operator_addressof_free_imp<_Tp>::value>
 {};
 
 #endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp?rev=221395&r1=221394&r2=221395&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp Wed Nov  5 14:59:18 2014
@@ -40,6 +40,10 @@ struct E
     constexpr C operator&() const;
 };
 
+struct F {};
+
+constexpr F* operator&(F const &) { return nullptr; }
+
 #endif  // _LIBCPP_HAS_NO_CONSTEXPR
 
 int main()
@@ -49,5 +53,6 @@ int main()
     static_assert(std::__has_operator_addressof<A>::value == false, "");
     static_assert(std::__has_operator_addressof<B>::value == true, "");
     static_assert(std::__has_operator_addressof<E>::value == true, "");
+    static_assert(std::__has_operator_addressof<F>::value == true, "");
 #endif  // _LIBCPP_HAS_NO_CONSTEXPR
 }





More information about the cfe-commits mailing list