diff --git a/libcxx/test/std/atomics/atomics.ref/increment_decrement.pass.cpp b/libcxx/test/std/atomics/atomics.ref/increment_decrement.pass.cpp index f26a0bdf3663a..15bf0ecda5363 100644 --- a/libcxx/test/std/atomics/atomics.ref/increment_decrement.pass.cpp +++ b/libcxx/test/std/atomics/atomics.ref/increment_decrement.pass.cpp @@ -42,43 +42,78 @@ constexpr bool does_not_have_increment_nor_decrement_operators() { template struct TestDoesNotHaveIncrementDecrement { - void operator()() const { static_assert(does_not_have_increment_nor_decrement_operators()); } + void operator()() const { static_assert(does_not_have_increment_nor_decrement_operators>()); } }; template struct TestIncrementDecrement { void operator()() const { - static_assert(std::is_integral_v); - - T x(T(1)); - std::atomic_ref const a(x); - - { - std::same_as decltype(auto) y = ++a; - assert(y == T(2)); - assert(x == T(2)); - ASSERT_NOEXCEPT(++a); - } - - { - std::same_as decltype(auto) y = --a; - assert(y == T(1)); - assert(x == T(1)); - ASSERT_NOEXCEPT(--a); - } - - { - std::same_as decltype(auto) y = a++; - assert(y == T(1)); - assert(x == T(2)); - ASSERT_NOEXCEPT(a++); - } - - { - std::same_as decltype(auto) y = a--; - assert(y == T(2)); - assert(x == T(1)); - ASSERT_NOEXCEPT(a--); + if constexpr (std::is_integral_v) { + T x(T(1)); + std::atomic_ref const a(x); + + { + std::same_as decltype(auto) y = ++a; + assert(y == T(2)); + assert(x == T(2)); + ASSERT_NOEXCEPT(++a); + } + + { + std::same_as decltype(auto) y = --a; + assert(y == T(1)); + assert(x == T(1)); + ASSERT_NOEXCEPT(--a); + } + + { + std::same_as decltype(auto) y = a++; + assert(y == T(1)); + assert(x == T(2)); + ASSERT_NOEXCEPT(a++); + } + + { + std::same_as decltype(auto) y = a--; + assert(y == T(2)); + assert(x == T(1)); + ASSERT_NOEXCEPT(a--); + } + } else if constexpr (std::is_pointer_v) { + using U = std::remove_pointer_t; + U t[9] = {}; + T p{&t[1]}; + std::atomic_ref const a(p); + + { + std::same_as decltype(auto) y = ++a; + assert(y == &t[2]); + assert(p == &t[2]); + ASSERT_NOEXCEPT(++a); + } + + { + std::same_as decltype(auto) y = --a; + assert(y == &t[1]); + assert(p == &t[1]); + ASSERT_NOEXCEPT(--a); + } + + { + std::same_as decltype(auto) y = a++; + assert(y == &t[1]); + assert(p == &t[2]); + ASSERT_NOEXCEPT(a++); + } + + { + std::same_as decltype(auto) y = a--; + assert(y == &t[2]); + assert(p == &t[1]); + ASSERT_NOEXCEPT(a--); + } + } else { + static_assert(std::is_void_v); } } }; @@ -88,7 +123,7 @@ int main(int, char**) { TestEachFloatingPointType()(); - TestEachPointerType()(); + TestEachPointerType()(); TestDoesNotHaveIncrementDecrement()(); TestDoesNotHaveIncrementDecrement()();