diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-05-25 00:22:33 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-05-25 00:22:33 +0000 |
commit | 29b75d6986caa3f9c12667272d4c65f3c7610e24 (patch) | |
tree | c8b8dba6872325e2da83969cc85ed43b96fcb394 | |
parent | 269eec03d6a4a65be91ef24bc297b9d241148c60 (diff) | |
download | bcm5719-llvm-29b75d6986caa3f9c12667272d4c65f3c7610e24.tar.gz bcm5719-llvm-29b75d6986caa3f9c12667272d4c65f3c7610e24.zip |
Add some constexpr tests for optional's move/copy ctor
llvm-svn: 303824
-rw-r--r-- | libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp | 13 | ||||
-rw-r--r-- | libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp | 14 |
2 files changed, 27 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp index 76c1fb82b86..6b4283a2854 100644 --- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp @@ -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); diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp index 09aaa0561b5..82acdd9d775 100644 --- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp @@ -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)); |