Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][test] Mark optional test functions as TEST_CONSTEXPR_CXX20 #94172

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

StephanTLavavej
Copy link
Member

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_asserts are properly guarded:

#if TEST_STD_VER > 17
static_assert(test_empty_emplace());
#endif

#if TEST_STD_VER >= 20
static_assert(check_reset());
#endif

Found while running libc++'s tests with MSVC's STL, as we activate our constexpr here for C++20 and above.

@StephanTLavavej StephanTLavavej requested a review from a team as a code owner June 2, 2024 21:16
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2024

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes

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_asserts are properly guarded:

#if TEST_STD_VER > 17
static_assert(test_empty_emplace());
#endif

#if TEST_STD_VER >= 20
static_assert(check_reset());
#endif

Found while running libc++'s tests with MSVC's STL, as we activate our constexpr here for C++20 and above.


Full diff: https://github.com/llvm/llvm-project/pull/94172.diff

2 Files Affected:

  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp (+1-1)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.mod/reset.pass.cpp (+1-1)
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..631052cad94b9 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,7 +210,7 @@ void test_on_test_type() {
     }
 }
 
-constexpr bool test_empty_emplace()
+TEST_CONSTEXPR_CXX20 bool test_empty_emplace()
 {
     optional<const int> opt;
     auto &v = opt.emplace(42);
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..c8c0b01060608 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,7 +31,7 @@ struct X
 
 bool X::dtor_called = false;
 
-constexpr bool check_reset()
+TEST_CONSTEXPR_CXX20 bool check_reset()
 {
     {
         optional<int> opt;

Copy link

github-actions bot commented Jun 2, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@philnik777 philnik777 merged commit 84742cd into llvm:main Jun 3, 2024
54 of 57 checks passed
@StephanTLavavej StephanTLavavej deleted the constexpr-optional branch June 3, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants