diff options
Diffstat (limited to 'libcxx/test/std/utilities/variant/variant.variant/variant.ctor')
-rw-r--r-- | libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp | 28 | ||||
-rw-r--r-- | libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp | 28 |
2 files changed, 32 insertions, 24 deletions
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp index 9e1e777256de..6eeec69c891c 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp @@ -22,7 +22,7 @@ // template <class ...Types> class variant; -// variant(variant const&); +// variant(variant const&); // constexpr in C++20 #include <cassert> #include <type_traits> @@ -126,7 +126,8 @@ void test_copy_ctor_sfinae() { static_assert(!std::is_copy_constructible<V>::value, ""); } - // The following tests are for not-yet-standardized behavior (P0602): + // Make sure we properly propagate triviality (see P0602R4). +#if TEST_STD_VER > 17 { using V = std::variant<int, long>; static_assert(std::is_trivially_copy_constructible<V>::value, ""); @@ -144,6 +145,7 @@ void test_copy_ctor_sfinae() { using V = std::variant<int, TCopyNTMove>; static_assert(std::is_trivially_copy_constructible<V>::value, ""); } +#endif // > C++17 } void test_copy_ctor_basic() { @@ -174,7 +176,8 @@ void test_copy_ctor_basic() { assert(std::get<1>(v2).value == 42); } - // The following tests are for not-yet-standardized behavior (P0602): + // Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4). +#if TEST_STD_VER > 17 { constexpr std::variant<int> v(std::in_place_index<0>, 42); static_assert(v.index() == 0, ""); @@ -217,6 +220,7 @@ void test_copy_ctor_basic() { static_assert(v2.index() == 1, ""); static_assert(std::get<1>(v2).value == 42, ""); } +#endif // > C++17 } void test_copy_ctor_valueless_by_exception() { @@ -231,17 +235,16 @@ void test_copy_ctor_valueless_by_exception() { } template <size_t Idx> -constexpr bool test_constexpr_copy_ctor_extension_imp( - std::variant<long, void*, const int> const& v) -{ +constexpr bool test_constexpr_copy_ctor_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() { - // NOTE: This test is for not yet standardized behavior. (P0602) +void test_constexpr_copy_ctor() { + // Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4). +#if TEST_STD_VER > 17 using V = std::variant<long, void*, const int>; #ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE static_assert(std::is_trivially_destructible<V>::value, ""); @@ -252,16 +255,17 @@ void test_constexpr_copy_ctor_extension() { #else // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE static_assert(std::is_trivially_copyable<V>::value, ""); #endif // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE - 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)), ""); + static_assert(test_constexpr_copy_ctor_imp<0>(V(42l)), ""); + static_assert(test_constexpr_copy_ctor_imp<1>(V(nullptr)), ""); + static_assert(test_constexpr_copy_ctor_imp<2>(V(101)), ""); +#endif // > C++17 } int main() { test_copy_ctor_basic(); test_copy_ctor_valueless_by_exception(); test_copy_ctor_sfinae(); - test_constexpr_copy_ctor_extension(); + test_constexpr_copy_ctor(); #if 0 // disable this for the moment; it fails on older compilers. // Need to figure out which compilers will support it. diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp index e6cdb0e96739..f59367109671 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp @@ -22,7 +22,7 @@ // template <class ...Types> class variant; -// variant(variant&&) noexcept(see below); +// variant(variant&&) noexcept(see below); // constexpr in C++20 #include <cassert> #include <string> @@ -147,7 +147,8 @@ void test_move_ctor_sfinae() { static_assert(!std::is_move_constructible<V>::value, ""); } - // The following tests are for not-yet-standardized behavior (P0602): + // Make sure we properly propagate triviality (see P0602R4). +#if TEST_STD_VER > 17 { using V = std::variant<int, long>; static_assert(std::is_trivially_move_constructible<V>::value, ""); @@ -165,6 +166,7 @@ void test_move_ctor_sfinae() { using V = std::variant<int, TMoveNTCopy>; static_assert(std::is_trivially_move_constructible<V>::value, ""); } +#endif // > C++17 } template <typename T> @@ -214,7 +216,8 @@ void test_move_ctor_basic() { assert(std::get<1>(v2).value == 42); } - // The following tests are for not-yet-standardized behavior (P0602): + // Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4). +#if TEST_STD_VER > 17 { struct { constexpr Result<int> operator()() const { @@ -287,6 +290,7 @@ void test_move_ctor_basic() { static_assert(result.index == 1, ""); static_assert(result.value.value == 42, ""); } +#endif // > C++17 } void test_move_ctor_valueless_by_exception() { @@ -300,9 +304,7 @@ void test_move_ctor_valueless_by_exception() { } template <size_t Idx> -constexpr bool test_constexpr_ctor_extension_imp( - std::variant<long, void*, const int> const& v) -{ +constexpr bool test_constexpr_ctor_imp(std::variant<long, void*, const int> const& v) { auto copy = v; auto v2 = std::move(copy); return v2.index() == v.index() && @@ -310,8 +312,9 @@ constexpr bool test_constexpr_ctor_extension_imp( std::get<Idx>(v2) == std::get<Idx>(v); } -void test_constexpr_move_ctor_extension() { - // NOTE: This test is for not yet standardized behavior. (P0602) +void test_constexpr_move_ctor() { + // Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4). +#if TEST_STD_VER > 17 using V = std::variant<long, void*, const int>; #ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE static_assert(std::is_trivially_destructible<V>::value, ""); @@ -323,9 +326,10 @@ void test_constexpr_move_ctor_extension() { static_assert(std::is_trivially_copyable<V>::value, ""); #endif // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE 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)), ""); + static_assert(test_constexpr_ctor_imp<0>(V(42l)), ""); + static_assert(test_constexpr_ctor_imp<1>(V(nullptr)), ""); + static_assert(test_constexpr_ctor_imp<2>(V(101)), ""); +#endif // > C++17 } int main() { @@ -333,5 +337,5 @@ int main() { test_move_ctor_valueless_by_exception(); test_move_noexcept(); test_move_ctor_sfinae(); - test_constexpr_move_ctor_extension(); + test_constexpr_move_ctor(); } |