Add some constexpr tests for optional's move/copy ctor
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@303824 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
index 76c1fb8..6b4283a 100644
--- a/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
+++ b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
@@ -32,6 +32,16 @@
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 @@
{
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);
diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
index 09aaa05..82acdd9 100644
--- a/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
+++ b/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
@@ -41,6 +41,17 @@
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 @@
{
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));