[libcxx-commits] [libcxx] [libc++] Make `constexpr std::variant`. Implement P2231R1 (PR #83335)
    Louis Dionne via libcxx-commits 
    libcxx-commits at lists.llvm.org
       
    Fri Mar  1 09:52:57 PST 2024
    
    
  
================
@@ -298,23 +279,29 @@ void test_T_assignment_performs_assignment() {
 #endif // TEST_HAS_NO_EXCEPTIONS
 }
 
-void test_T_assignment_vector_bool() {
+TEST_CONSTEXPR_CXX20 bool test_T_assignment_vector_bool() {
 #ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
   std::vector<bool> vec = {true};
   std::variant<bool, int> v;
   v = vec[0];
   assert(v.index() == 0);
   assert(std::get<0>(v) == true);
 #endif
+  return true;
 }
 
 int main(int, char**) {
   test_T_assignment_basic();
+  test_T_assignment_basic_no_constexpr();
----------------
ldionne wrote:
I would try to follow the pattern where we do:
```
int main() {
  test();
  test_non_constexpr();
#if TEST_STD_VER >= 20
  static_assert(test());
#endif
}
```
So that means you'd refactor e.g. the exceptions tests into the non-constexpr part, but keep everything you can in the common part. That would include the compile-time only tests. Technically there is no benefit in "running" those twice, but I think consistency should win here.
This comment applies to all tests.
https://github.com/llvm/llvm-project/pull/83335
    
    
More information about the libcxx-commits
mailing list