[libcxx] r222132 - Add tests to ensure that reference_wrapper<T> is trivially copyable. This was added to C++1z with the adoption of N4277, but libc++ already implemented it as a conforming extension. No code changes were needed, just more tests.

Marshall Clow mclow.lists at gmail.com
Mon Nov 17 07:04:47 PST 2014


Author: marshall
Date: Mon Nov 17 09:04:46 2014
New Revision: 222132

URL: http://llvm.org/viewvc/llvm-project?rev=222132&view=rev
Log:
Add tests to ensure that reference_wrapper<T> is trivially copyable. This was added to C++1z with the adoption of N4277, but libc++ already implemented it as a conforming extension. No code changes were needed, just more tests.

Modified:
    libcxx/trunk/test/utilities/function.objects/refwrap/type_properties.pass.cpp

Modified: libcxx/trunk/test/utilities/function.objects/refwrap/type_properties.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/function.objects/refwrap/type_properties.pass.cpp?rev=222132&r1=222131&r2=222132&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/function.objects/refwrap/type_properties.pass.cpp (original)
+++ libcxx/trunk/test/utilities/function.objects/refwrap/type_properties.pass.cpp Mon Nov 17 09:04:46 2014
@@ -16,12 +16,43 @@
 
 #include <functional>
 #include <type_traits>
+#include <string>
 
-int main()
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+class MoveOnly
+{
+    MoveOnly(const MoveOnly&);
+    MoveOnly& operator=(const MoveOnly&);
+
+    int data_;
+public:
+    MoveOnly(int data = 1) : data_(data) {}
+    MoveOnly(MoveOnly&& x)
+        : data_(x.data_) {x.data_ = 0;}
+    MoveOnly& operator=(MoveOnly&& x)
+        {data_ = x.data_; x.data_ = 0; return *this;}
+
+    int get() const {return data_;}
+};
+#endif
+
+
+template <class T>
+void test()
 {
-    typedef std::reference_wrapper<int> T;
-    static_assert(std::is_copy_constructible<T>::value, "");
-    static_assert(std::is_copy_assignable<T>::value, "");
+    typedef std::reference_wrapper<T> Wrap;
+    static_assert(std::is_copy_constructible<Wrap>::value, "");
+    static_assert(std::is_copy_assignable<Wrap>::value, "");
     // Extension up for standardization: See N4151.
-    static_assert(std::is_trivially_copyable<T>::value, "");
+    static_assert(std::is_trivially_copyable<Wrap>::value, "");
+}
+
+int main()
+{
+    test<int>();
+    test<double>();
+    test<std::string>(); 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    test<MoveOnly>(); 
+#endif
 }





More information about the cfe-commits mailing list