[libcxx] r303824 - Add some constexpr tests for optional's move/copy ctor

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 17:22:33 PDT 2017


Author: marshall
Date: Wed May 24 19:22:33 2017
New Revision: 303824

URL: http://llvm.org/viewvc/llvm-project?rev=303824&view=rev
Log:
Add some constexpr tests for optional's move/copy ctor

Modified:
    libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
    libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp

Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp?rev=303824&r1=303823&r2=303824&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp Wed May 24 19:22:33 2017
@@ -32,6 +32,16 @@ void test(InitArgs&&... args)
         assert(*lhs == *rhs);
 }
 
+template <class T, class ...InitArgs>
+constexpr bool constexpr_test(InitArgs&&... args)
+{
+    static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
+    const optional<T> rhs(std::forward<InitArgs>(args)...);
+    optional<T> lhs = rhs;
+    return (lhs.has_value() == rhs.has_value()) &&
+           (lhs.has_value() ? *lhs == *rhs : true);
+}
+
 void test_throwing_ctor() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
     struct Z {
@@ -108,6 +118,9 @@ int main()
 {
     test<int>();
     test<int>(3);
+    static_assert(constexpr_test<int>(), "" );
+    static_assert(constexpr_test<int>(3), "" );
+
     {
         const optional<const int> o(42);
         optional<const int> o2(o);

Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp?rev=303824&r1=303823&r2=303824&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp Wed May 24 19:22:33 2017
@@ -41,6 +41,17 @@ void test(InitArgs&&... args)
         assert(*lhs == *orig);
 }
 
+template <class T, class ...InitArgs>
+constexpr bool constexpr_test(InitArgs&&... args)
+{
+    static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
+    const optional<T> orig(std::forward<InitArgs>(args)...);
+    optional<T> rhs(orig);
+    optional<T> lhs = std::move(rhs);
+    return (lhs.has_value() == orig.has_value()) &&
+           (lhs.has_value() ? *lhs == *orig : true);
+}
+
 void test_throwing_ctor() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
     struct Z {
@@ -144,6 +155,9 @@ int main()
 {
     test<int>();
     test<int>(3);
+    static_assert(constexpr_test<int>(), "" );
+    static_assert(constexpr_test<int>(3), "" );
+	
     {
         optional<const int> o(42);
         optional<const int> o2(std::move(o));




More information about the cfe-commits mailing list