[cfe-commits] [libcxx] r162644 - /libcxx/trunk/include/type_traits

Howard Hinnant hhinnant at apple.com
Sat Aug 25 08:06:50 PDT 2012


Author: hhinnant
Date: Sat Aug 25 10:06:50 2012
New Revision: 162644

URL: http://llvm.org/viewvc/llvm-project?rev=162644&view=rev
Log:
Michel Morin:  My previous fix for C++03 was incomplete. 
It does not consider user-defined conversions that convert an rvalue
into an lvalue and works incorrectly for types with such a conversion
operator.
For example, 

    struct foo
    {
        operator int&();
    };

 returns false_type. 
Attached a patch that fixes this problem. 
http://llvm.org/bugs/show_bug.cgi?id=13601

Modified:
    libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=162644&r1=162643&r2=162644&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Sat Aug 25 10:06:50 2012
@@ -607,6 +607,20 @@
 
 template <class _Tp> struct _LIBCPP_VISIBLE is_abstract : public __libcpp_abstract<_Tp> {};
 
+// is_base_of
+
+#ifdef _LIBCP_HAS_IS_BASE_OF
+
+template <class _Bp, class _Dp>
+struct _LIBCPP_VISIBLE is_base_of
+    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
+
+#else  // __has_feature(is_base_of)
+
+#error is_base_of not implemented.
+
+#endif  // __has_feature(is_base_of)
+
 // is_convertible
 
 #if __has_feature(is_convertible_to)
@@ -660,7 +674,10 @@
         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
          && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
               && (!is_const<typename remove_reference<_T2>::type>::value
-                  || is_volatile<typename remove_reference<_T2>::type>::value))
+                  || is_volatile<typename remove_reference<_T2>::type>::value)
+                  && (is_same<typename remove_cv<_T1>::type,
+                              typename remove_cv<typename remove_reference<_T2>::type>::type>::value
+                      || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
 #endif
     >
 {};
@@ -723,20 +740,6 @@
 
 #endif  // __has_feature(is_convertible_to)
 
-// is_base_of
-
-#ifdef _LIBCP_HAS_IS_BASE_OF
-
-template <class _Bp, class _Dp>
-struct _LIBCPP_VISIBLE is_base_of
-    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
-
-#else  // __has_feature(is_base_of)
-
-#error is_base_of not implemented.
-
-#endif  // __has_feature(is_base_of)
-
 // is_empty
 
 #if __has_feature(is_empty)





More information about the cfe-commits mailing list