[libcxx-commits] [libcxx] 84742cd - [libc++][test] Mark `optional` test functions as `TEST_CONSTEXPR_CXX20` (#94172)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 3 01:08:49 PDT 2024
Author: Stephan T. Lavavej
Date: 2024-06-03T10:08:46+02:00
New Revision: 84742cd867b0e7e76da6bdc08cc7c56beac86168
URL: https://github.com/llvm/llvm-project/commit/84742cd867b0e7e76da6bdc08cc7c56beac86168
DIFF: https://github.com/llvm/llvm-project/commit/84742cd867b0e7e76da6bdc08cc7c56beac86168.diff
LOG: [libc++][test] Mark `optional` test functions as `TEST_CONSTEXPR_CXX20` (#94172)
[P2231R1](https://wg21.link/P2231R1) "Missing `constexpr` in
`std::optional` and `std::variant`" was accepted as a C++20 Defect
Report, not a C++17 Defect Report. Accordingly, `test_empty_emplace()`
and `check_reset()` should be marked as `TEST_CONSTEXPR_CXX20`. Note
that their `static_assert`s are properly guarded:
https://github.com/llvm/llvm-project/blob/4ce65423be0ba1d90c11b6a79981d6314e1cf36d/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp#L270-L272
https://github.com/llvm/llvm-project/blob/4ce65423be0ba1d90c11b6a79981d6314e1cf36d/libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp#L53-L55
Found while running libc++'s tests with MSVC's STL, as we activate our
`constexpr` here for C++20 and above.
Added:
Modified:
libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
index 17a1e94b0ba6e..245d8ff3d2146 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
@@ -210,16 +210,15 @@ void test_on_test_type() {
}
}
-constexpr bool test_empty_emplace()
-{
- optional<const int> opt;
- auto &v = opt.emplace(42);
- static_assert( std::is_same_v<const int&, decltype(v)>, "" );
- assert(*opt == 42);
- assert( v == 42);
- opt.emplace();
- assert(*opt == 0);
- return true;
+TEST_CONSTEXPR_CXX20 bool test_empty_emplace() {
+ optional<const int> opt;
+ auto& v = opt.emplace(42);
+ static_assert(std::is_same_v<const int&, decltype(v)>, "");
+ assert(*opt == 42);
+ assert(v == 42);
+ opt.emplace();
+ assert(*opt == 0);
+ return true;
}
int main(int, char**)
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp
index 112ee213b42a6..7029b37cbecd7 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp
@@ -31,20 +31,19 @@ struct X
bool X::dtor_called = false;
-constexpr bool check_reset()
-{
- {
- optional<int> opt;
- static_assert(noexcept(opt.reset()) == true, "");
- opt.reset();
- assert(static_cast<bool>(opt) == false);
- }
- {
- optional<int> opt(3);
- opt.reset();
- assert(static_cast<bool>(opt) == false);
- }
- return true;
+TEST_CONSTEXPR_CXX20 bool check_reset() {
+ {
+ optional<int> opt;
+ static_assert(noexcept(opt.reset()) == true, "");
+ opt.reset();
+ assert(static_cast<bool>(opt) == false);
+ }
+ {
+ optional<int> opt(3);
+ opt.reset();
+ assert(static_cast<bool>(opt) == false);
+ }
+ return true;
}
int main(int, char**)
More information about the libcxx-commits
mailing list