[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 8 08:38:23 PST 2024
================
@@ -224,265 +204,293 @@ void test_swap_valueless_by_exception() {
#endif
}
-void test_swap_same_alternative() {
+TEST_CONSTEXPR_CXX20 void test_swap_same_alternative() {
{
- using T = ThrowingTypeWithNothrowSwap;
- using V = std::variant<T, int>;
- T::reset();
- V v1(std::in_place_index<0>, 42);
- V v2(std::in_place_index<0>, 100);
+ using V = std::variant<ThrowingTypeWithNothrowSwap, int>;
+ int move_called = 0;
+ int move_assign_called = 0;
+ int swap_called = 0;
+ V v1(std::in_place_index<0>, 42, &move_called, &move_assign_called, &swap_called);
+ V v2(std::in_place_index<0>, 100, &move_called, &move_assign_called, &swap_called);
v1.swap(v2);
- assert(T::swap_called == 1);
+ assert(swap_called == 1);
assert(std::get<0>(v1).value == 100);
assert(std::get<0>(v2).value == 42);
swap(v1, v2);
- assert(T::swap_called == 2);
+ assert(swap_called == 2);
assert(std::get<0>(v1).value == 42);
assert(std::get<0>(v2).value == 100);
+
+ assert(move_called == 0);
+ assert(move_assign_called == 0);
}
{
- using T = NothrowMoveable;
- using V = std::variant<T, int>;
- T::reset();
- V v1(std::in_place_index<0>, 42);
- V v2(std::in_place_index<0>, 100);
+ using V = std::variant<NothrowMoveable, int>;
+ int move_called = 0;
+ int move_assign_called = 0;
+ int swap_called = 0;
+ V v1(std::in_place_index<0>, 42, &move_called, &move_assign_called, &swap_called);
+ V v2(std::in_place_index<0>, 100, &move_called, &move_assign_called, &swap_called);
v1.swap(v2);
- assert(T::swap_called == 0);
- assert(T::move_called == 1);
- assert(T::move_assign_called == 2);
+ assert(swap_called == 0);
+ assert(move_called == 1);
+ assert(move_assign_called == 2);
assert(std::get<0>(v1).value == 100);
assert(std::get<0>(v2).value == 42);
- T::reset();
+
+ move_called = 0;
+ move_assign_called = 0;
+ swap_called = 0;
+
swap(v1, v2);
- assert(T::swap_called == 0);
- assert(T::move_called == 1);
- assert(T::move_assign_called == 2);
+ assert(swap_called == 0);
+ assert(move_called == 1);
+ assert(move_assign_called == 2);
assert(std::get<0>(v1).value == 42);
assert(std::get<0>(v2).value == 100);
}
+}
+
+void test_swap_same_alternative_throws(){
----------------
ldionne wrote:
Looks like we are hitting a clang-format bug. This seems to reproduce it:
```
#define TEST_CONSTEXPR_CXX20 constexpr
void f(){
#ifndef TEST_HAS_NO_EXCEPTIONS
{using Foo = int;
just_to_show_weird_indentation();
}
#endif
}
TEST_CONSTEXPR_CXX20 void g() {}
```
Can you file a clang-format bug?
https://github.com/llvm/llvm-project/pull/83335
More information about the libcxx-commits
mailing list