[libcxx] r218286 - Fix some type-traits (is_assignable, etc) dealing with classes that take non-const references as 'right hand side'. Add tests. Fixes PR# 20836

Marshall Clow mclow.lists at gmail.com
Mon Sep 22 16:58:01 PDT 2014


Author: marshall
Date: Mon Sep 22 18:58:00 2014
New Revision: 218286

URL: http://llvm.org/viewvc/llvm-project?rev=218286&view=rev
Log:
Fix some type-traits (is_assignable, etc) dealing with classes that take non-const references as 'right hand side'. Add tests. Fixes PR# 20836

Modified:
    libcxx/trunk/include/type_traits
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Sep 22 18:58:00 2014
@@ -1523,7 +1523,7 @@ struct is_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
-                     const typename add_lvalue_reference<_Tp>::type> {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_move_assignable
 
@@ -2637,8 +2637,8 @@ struct _LIBCPP_TYPE_VIS_ONLY is_default_
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible
-    : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
-    {};
+    : public is_constructible<_Tp, 
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_move_constructible
 
@@ -2842,8 +2842,7 @@ struct is_trivially_assignable<_Tp&, _Tp
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
-                               const typename add_lvalue_reference<_Tp>::type>
-    {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_trivially_move_assignable
 
@@ -3034,8 +3033,8 @@ template <class _Tp> struct _LIBCPP_TYPE
 // is_nothrow_copy_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
-    : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
-    {};
+    : public is_nothrow_constructible<_Tp,
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_nothrow_move_constructible
 
@@ -3119,8 +3118,7 @@ struct is_nothrow_assignable<_Tp&, _Tp&&
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
-                               const typename add_lvalue_reference<_Tp>::type>
-    {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_nothrow_move_assignable
 

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp Mon Sep 22 18:58:00 2014
@@ -52,6 +52,11 @@ class B
     B& operator=(const B&);
 };
 
+struct C
+{
+    void operator=(C&);  // not const
+};
+
 int main()
 {
     test_is_copy_assignable<int> ();
@@ -71,4 +76,5 @@ int main()
     test_is_not_copy_assignable<B> ();
 #endif
     test_is_not_copy_assignable<void> ();
+    test_is_not_copy_assignable<C> ();
 }

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp Mon Sep 22 18:58:00 2014
@@ -58,6 +58,12 @@ class B
     B(const B&);
 };
 
+struct C
+{
+    C(C&);  // not const
+    void operator=(C&);  // not const
+};
+
 int main()
 {
     test_is_copy_constructible<A>();
@@ -75,6 +81,7 @@ int main()
     test_is_not_copy_constructible<char[]>();
     test_is_not_copy_constructible<void>();
     test_is_not_copy_constructible<Abstract>();
+    test_is_not_copy_constructible<C>();
 #if __has_feature(cxx_access_control_sfinae) 
     test_is_not_copy_constructible<B>();
 #endif

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp Mon Sep 22 18:58:00 2014
@@ -34,6 +34,11 @@ struct B
     void operator=(A);
 };
 
+struct C
+{
+    void operator=(C&);  // not const
+};
+
 int main()
 {
     test_is_nothrow_assignable<int&, int&> ();
@@ -46,4 +51,5 @@ int main()
     test_is_not_nothrow_assignable<int, int> ();
     test_is_not_nothrow_assignable<B, A> ();
     test_is_not_nothrow_assignable<A, B> ();
+    test_is_not_nothrow_assignable<C, C&> ();
 }

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp Mon Sep 22 18:58:00 2014
@@ -70,6 +70,12 @@ struct A
     A(const A&);
 };
 
+struct C
+{
+    C(C&);  // not const
+    void operator=(C&);  // not const
+};
+
 int main()
 {
     test_is_nothrow_constructible<int> ();
@@ -80,4 +86,5 @@ int main()
     test_is_not_nothrow_constructible<A, int> ();
     test_is_not_nothrow_constructible<A, int, double> ();
     test_is_not_nothrow_constructible<A> ();
+    test_is_not_nothrow_constructible<C> ();
 }

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp?rev=218286&r1=218285&r2=218286&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp Mon Sep 22 18:58:00 2014
@@ -34,6 +34,11 @@ struct B
     void operator=(A);
 };
 
+struct C
+{
+    void operator=(C&);  // not const
+};
+
 int main()
 {
     test_is_trivially_assignable<int&, int&> ();
@@ -44,4 +49,5 @@ int main()
     test_is_not_trivially_assignable<int, int> ();
     test_is_not_trivially_assignable<B, A> ();
     test_is_not_trivially_assignable<A, B> ();
+    test_is_not_trivially_assignable<C&, C&> ();
 }





More information about the cfe-commits mailing list