Skip to content

Commit 84742cd

Browse files
[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.
1 parent f4a7f81 commit 84742cd

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,15 @@ void test_on_test_type() {
210210
}
211211
}
212212

213-
constexpr bool test_empty_emplace()
214-
{
215-
optional<const int> opt;
216-
auto &v = opt.emplace(42);
217-
static_assert( std::is_same_v<const int&, decltype(v)>, "" );
218-
assert(*opt == 42);
219-
assert( v == 42);
220-
opt.emplace();
221-
assert(*opt == 0);
222-
return true;
213+
TEST_CONSTEXPR_CXX20 bool test_empty_emplace() {
214+
optional<const int> opt;
215+
auto& v = opt.emplace(42);
216+
static_assert(std::is_same_v<const int&, decltype(v)>, "");
217+
assert(*opt == 42);
218+
assert(v == 42);
219+
opt.emplace();
220+
assert(*opt == 0);
221+
return true;
223222
}
224223

225224
int main(int, char**)

libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ struct X
3131

3232
bool X::dtor_called = false;
3333

34-
constexpr bool check_reset()
35-
{
36-
{
37-
optional<int> opt;
38-
static_assert(noexcept(opt.reset()) == true, "");
39-
opt.reset();
40-
assert(static_cast<bool>(opt) == false);
41-
}
42-
{
43-
optional<int> opt(3);
44-
opt.reset();
45-
assert(static_cast<bool>(opt) == false);
46-
}
47-
return true;
34+
TEST_CONSTEXPR_CXX20 bool check_reset() {
35+
{
36+
optional<int> opt;
37+
static_assert(noexcept(opt.reset()) == true, "");
38+
opt.reset();
39+
assert(static_cast<bool>(opt) == false);
40+
}
41+
{
42+
optional<int> opt(3);
43+
opt.reset();
44+
assert(static_cast<bool>(opt) == false);
45+
}
46+
return true;
4847
}
4948

5049
int main(int, char**)

0 commit comments

Comments
 (0)