From 6d52b3b76ce5103985d1ab8bf3ad18b0d90d954f Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 25 May 2017 00:22:33 +0000 Subject: [PATCH] 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 --- .../optional.object.ctor/copy.pass.cpp | 13 +++++++++++++ .../optional.object.ctor/move.pass.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+) 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 76c1fb82b..6b4283a28 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 @@ void test(InitArgs&&... args) assert(*lhs == *rhs); } +template +constexpr bool constexpr_test(InitArgs&&... args) +{ + static_assert( std::is_trivially_copy_constructible_v, ""); // requirement + const optional rhs(std::forward(args)...); + optional 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(); test(3); + static_assert(constexpr_test(), "" ); + static_assert(constexpr_test(3), "" ); + { const optional o(42); optional 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 09aaa0561..82acdd9d7 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 @@ void test(InitArgs&&... args) assert(*lhs == *orig); } +template +constexpr bool constexpr_test(InitArgs&&... args) +{ + static_assert( std::is_trivially_copy_constructible_v, ""); // requirement + const optional orig(std::forward(args)...); + optional rhs(orig); + optional 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(); test(3); + static_assert(constexpr_test(), "" ); + static_assert(constexpr_test(3), "" ); + { optional o(42); optional o2(std::move(o));