[libcxx] r288536 - Add tests for libc++'s constexpr variant copy/move extension

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 13:17:52 PST 2016


Author: ericwf
Date: Fri Dec  2 15:17:51 2016
New Revision: 288536

URL: http://llvm.org/viewvc/llvm-project?rev=288536&view=rev
Log:
Add tests for libc++'s constexpr variant copy/move extension

Modified:
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp?rev=288536&r1=288535&r2=288536&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp Fri Dec  2 15:17:51 2016
@@ -385,6 +385,29 @@ void test_copy_assignment_different_inde
 #endif
 }
 
+template <size_t NewIdx, class ValueType>
+constexpr bool test_constexpr_assign_extension_imp(
+    std::variant<long, void*, const int>&& v, ValueType&& new_value)
+{
+  const std::variant<long, void*, const int> cp(
+      std::forward<ValueType>(new_value));
+  v = cp;
+  return v.index() == NewIdx &&
+        std::get<NewIdx>(v) == std::get<NewIdx>(cp);
+}
+
+void test_constexpr_move_ctor_extension() {
+#ifdef _LIBCPP_VERSION
+  using V = std::variant<long, void*, int>;
+  static_assert(std::is_trivially_copyable<V>::value, "");
+  static_assert(std::is_trivially_copy_assignable<V>::value, "");
+  static_assert(test_constexpr_assign_extension_imp<0>(V(42l), 101l), "");
+  static_assert(test_constexpr_assign_extension_imp<0>(V(nullptr), 101l), "");
+  static_assert(test_constexpr_assign_extension_imp<1>(V(42l), nullptr), "");
+  static_assert(test_constexpr_assign_extension_imp<2>(V(42l), 101), "");
+#endif
+}
+
 int main() {
   test_copy_assignment_empty_empty();
   test_copy_assignment_non_empty_empty();
@@ -393,4 +416,5 @@ int main() {
   test_copy_assignment_different_index();
   test_copy_assignment_sfinae();
   test_copy_assignment_not_noexcept();
+  test_constexpr_copy_assignment_extension();
 }

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp?rev=288536&r1=288535&r2=288536&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp Fri Dec  2 15:17:51 2016
@@ -308,6 +308,29 @@ void test_move_assignment_different_inde
 #endif
 }
 
+template <size_t NewIdx, class ValueType>
+constexpr bool test_constexpr_assign_extension_imp(
+    std::variant<long, void*, const int>&& v, ValueType&& new_value)
+{
+  std::variant<long, void*, const int> v2(
+      std::forward<ValueType>(new_value));
+  const auto cp = v2;
+  v = std::move(v2);
+  return v.index() == NewIdx &&
+        std::get<NewIdx>(v) == std::get<NewIdx>(cp);
+}
+
+void test_constexpr_move_ctor_extension() {
+#ifdef _LIBCPP_VERSION
+  using V = std::variant<long, void*, int>;
+  static_assert(std::is_trivially_copyable<V>::value, "");
+  static_assert(std::is_trivially_move_assignable<V>::value, "");
+  static_assert(test_constexpr_assign_extension_imp<0>(V(42l), 101l), "");
+  static_assert(test_constexpr_assign_extension_imp<0>(V(nullptr), 101l), "");
+  static_assert(test_constexpr_assign_extension_imp<1>(V(42l), nullptr), "");
+  static_assert(test_constexpr_assign_extension_imp<2>(V(42l), 101), "");
+#endif
+}
 int main() {
   test_move_assignment_empty_empty();
   test_move_assignment_non_empty_empty();
@@ -316,4 +339,5 @@ int main() {
   test_move_assignment_different_index();
   test_move_assignment_sfinae();
   test_move_assignment_noexcept();
+  test_constexpr_move_assignment_extension();
 }

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp?rev=288536&r1=288535&r2=288536&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp Fri Dec  2 15:17:51 2016
@@ -130,8 +130,30 @@ void test_copy_ctor_valueless_by_excepti
 #endif
 }
 
+template <size_t Idx>
+constexpr bool test_constexpr_copy_ctor_extension_imp(
+    std::variant<long, void*, const int> const& v)
+{
+  auto v2 = v;
+  return v2.index() == v.index() &&
+         v2.index() == Idx &&
+        std::get<Idx>(v2) == std::get<Idx>(v);
+}
+
+void test_constexpr_copy_ctor_extension() {
+#ifdef _LIBCPP_VERSION
+  using V = std::variant<long, void*, const int>;
+  static_assert(std::is_trivially_copyable<V>::value, "");
+  static_assert(std::is_trivially_copy_constructible<V>::value, "");
+  static_assert(test_constexpr_copy_ctor_extension_imp<0>(V(42l)), "");
+  static_assert(test_constexpr_copy_ctor_extension_imp<1>(V(nullptr)), "");
+  static_assert(test_constexpr_copy_ctor_extension_imp<2>(V(101)), "");
+#endif
+}
+
 int main() {
   test_copy_ctor_basic();
   test_copy_ctor_valueless_by_exception();
   test_copy_ctor_sfinae();
+  test_constexpr_copy_ctor_extension();
 }

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp?rev=288536&r1=288535&r2=288536&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp Fri Dec  2 15:17:51 2016
@@ -166,9 +166,32 @@ void test_move_ctor_valueless_by_excepti
 #endif
 }
 
+template <size_t Idx>
+constexpr bool test_constexpr_ctor_extension_imp(
+    std::variant<long, void*, const int> const& v)
+{
+  auto copy = v;
+  auto v2 = std::move(copy);
+  return v2.index() == v.index() &&
+         v2.index() == Idx &&
+        std::get<Idx>(v2) == std::get<Idx>(v);
+}
+
+void test_constexpr_move_ctor_extension() {
+#ifdef _LIBCPP_VERSION
+  using V = std::variant<long, void*, const int>;
+  static_assert(std::is_trivially_copyable<V>::value, "");
+  static_assert(std::is_trivially_move_constructible<V>::value, "");
+  static_assert(test_constexpr_ctor_extension_imp<0>(V(42l)), "");
+  static_assert(test_constexpr_ctor_extension_imp<1>(V(nullptr)), "");
+  static_assert(test_constexpr_ctor_extension_imp<2>(V(101)), "");
+#endif
+}
+
 int main() {
   test_move_ctor_basic();
   test_move_ctor_valueless_by_exception();
   test_move_noexcept();
   test_move_ctor_sfinae();
+  test_constexpr_move_ctor_extension();
 }




More information about the cfe-commits mailing list