[libcxx-commits] [libcxx] affbb4d - [libc++] std::atomic primary template should not have a `difference_type` member type (#123236)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 21 09:53:14 PST 2025
Author: Damien L-G
Date: 2025-02-21T12:53:11-05:00
New Revision: affbb4d9cf6fc48ce44af4eee61fdb6528473788
URL: https://github.com/llvm/llvm-project/commit/affbb4d9cf6fc48ce44af4eee61fdb6528473788
DIFF: https://github.com/llvm/llvm-project/commit/affbb4d9cf6fc48ce44af4eee61fdb6528473788.diff
LOG: [libc++] std::atomic primary template should not have a `difference_type` member type (#123236)
The test would not check its absence and the code path intended for
pointer was never actually instantiated.
I added a few pointer types since there was no coverage.
---------
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
Added:
Modified:
libcxx/include/__atomic/atomic.h
libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp
libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp
libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp
libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp
libcxx/test/std/atomics/types.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__atomic/atomic.h b/libcxx/include/__atomic/atomic.h
index 975a479e20400..278d7f2854bae 100644
--- a/libcxx/include/__atomic/atomic.h
+++ b/libcxx/include/__atomic/atomic.h
@@ -40,6 +40,8 @@ struct __atomic_base // false
{
mutable __cxx_atomic_impl<_Tp> __a_;
+ using value_type = _Tp;
+
#if _LIBCPP_STD_VER >= 17
static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
#endif
@@ -145,6 +147,8 @@ template <class _Tp>
struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>;
+ using
diff erence_type = typename __base::value_type;
+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
@@ -229,8 +233,6 @@ struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > {
template <class _Tp>
struct atomic : public __atomic_base<_Tp> {
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
- using value_type = _Tp;
- using
diff erence_type = value_type;
#if _LIBCPP_STD_VER >= 20
_LIBCPP_HIDE_FROM_ABI atomic() = default;
@@ -258,8 +260,8 @@ struct atomic : public __atomic_base<_Tp> {
template <class _Tp>
struct atomic<_Tp*> : public __atomic_base<_Tp*> {
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>;
- using value_type = _Tp*;
- using
diff erence_type = ptr
diff _t;
+
+ using
diff erence_type = ptr
diff _t;
_LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
diff --git a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp
index fbe7dbbd6d9f0..320ef57dcb6f9 100644
--- a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp
+++ b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
// <atomic>
// template <class T>
@@ -63,12 +65,12 @@ struct S {
void member_function_pointer() {
{
volatile std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_add' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_add'}}
std::atomic_fetch_add(&fun, 0);
}
{
std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_add' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_add'}}
std::atomic_fetch_add(&fun, 0);
}
}
diff --git a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp
index 176a38c7c0f7f..bdd8089feb281 100644
--- a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp
+++ b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
// <atomic>
// template <class T>
@@ -66,12 +68,12 @@ struct S {
void member_function_pointer() {
{
volatile std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_add' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_add_explicit'}}
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed);
}
{
std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_add' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_add_explicit'}}
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed);
}
}
diff --git a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp
index 6f3039dab6697..2c9f89891d5be 100644
--- a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp
+++ b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
// <atomic>
// template <class T>
@@ -63,12 +65,12 @@ struct S {
void member_function_pointer() {
{
volatile std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_sub' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_sub'}}
std::atomic_fetch_sub(&fun, 0);
}
{
std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_sub' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_sub'}}
std::atomic_fetch_sub(&fun, 0);
}
}
diff --git a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp
index 1b3c58fa87551..88c42750b608a 100644
--- a/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp
+++ b/libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
// <atomic>
// template <class T>
@@ -66,12 +68,12 @@ struct S {
void member_function_pointer() {
{
volatile std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_sub' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_sub_explicit'}}
std::atomic_fetch_sub_explicit(&fun, 0, std::memory_order_relaxed);
}
{
std::atomic<void (S::*)(int)> fun;
- // expected-error@*:* {{no member named 'fetch_sub' in}}
+ // expected-error@*:* {{no matching function for call to 'atomic_fetch_sub_explicit'}}
std::atomic_fetch_sub_explicit(&fun, 0, std::memory_order_relaxed);
}
}
diff --git a/libcxx/test/std/atomics/types.pass.cpp b/libcxx/test/std/atomics/types.pass.cpp
index 33512c037804f..8737694e2a070 100644
--- a/libcxx/test/std/atomics/types.pass.cpp
+++ b/libcxx/test/std/atomics/types.pass.cpp
@@ -17,6 +17,9 @@
// typedef T value_type;
// };
+// atomic still has a
diff erence_type in the C++03 frozen headers
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
#include <atomic>
#include <chrono>
#include <cstdint>
@@ -29,163 +32,185 @@
# include <thread>
#endif
-template <class A, bool Integral>
-struct test_atomic
-{
- test_atomic()
- {
- A a; (void)a;
-#if TEST_STD_VER >= 17
- static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), "");
-#endif
- }
+// detect existence of the
diff erence_type member type
+template <class...>
+using myvoid_t = void;
+template <typename T, typename = void>
+struct has_
diff erence_type : std::false_type {};
+template <typename T>
+struct has_
diff erence_type<T, myvoid_t<typename T::
diff erence_type> > : std::true_type {};
+
+template <class T,
+ bool Integral = (std::is_integral<T>::value && !std::is_same<T, bool>::value),
+ bool Floating = std::is_floating_point<T>::value,
+ bool Pointer = std::is_pointer<T>::value>
+struct test_atomic {
+ test_atomic() {
+ static_assert(!Integral && !Floating && !Pointer, "");
+ using A = std::atomic<T>;
+ A a;
+ (void)a;
+ static_assert(std::is_same<typename A::value_type, T>::value, "");
+ static_assert(!has_
diff erence_type<A>::value, "");
+ }
};
-template <class A>
-struct test_atomic<A, true>
-{
- test_atomic()
- {
- A a; (void)a;
-#if TEST_STD_VER >= 17
- static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), "");
- static_assert((std::is_same_v<typename A::value_type, typename A::
diff erence_type>), "");
-#endif
- }
+template <class T>
+struct test_atomic<T, /*Integral=*/true, false, false> {
+ test_atomic() {
+ static_assert(!std::is_same<T, bool>::value, "");
+ using A = std::atomic<T>;
+ A a;
+ (void)a;
+ static_assert(std::is_same<typename A::value_type, T>::value, "");
+ static_assert(std::is_same<typename A::
diff erence_type, T>::value, "");
+ }
};
-template <class A>
-struct test_atomic<A*, false>
-{
- test_atomic()
- {
- A a; (void)a;
-#if TEST_STD_VER >= 17
- static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), "");
- static_assert((std::is_same_v<typename A::
diff erence_type, std::ptr
diff _t>), "");
+template <class T>
+struct test_atomic<T, false, /*Foating=*/true, false> {
+ test_atomic() {
+ using A = std::atomic<T>;
+ A a;
+ (void)a;
+ static_assert(std::is_same<typename A::value_type, T>::value, "");
+#if TEST_STD_VER >= 20
+ static_assert(std::is_same<typename A::
diff erence_type, T>::value, "");
+#else
+ static_assert(!has_
diff erence_type<A>::value, "");
#endif
- }
+ }
};
template <class T>
-void
-test()
-{
+struct test_atomic<T, false, false, /*Pointer=*/true> {
+ test_atomic() {
using A = std::atomic<T>;
-#if TEST_STD_VER >= 17
- static_assert((std::is_same_v<typename A::value_type, T>), "");
-#endif
- test_atomic<A, std::is_integral<T>::value && !std::is_same<T, bool>::value>();
+ A a;
+ (void)a;
+ static_assert(std::is_same<typename A::value_type, T>::value, "");
+ static_assert(std::is_same<typename A::
diff erence_type, std::ptr
diff _t>::value, "");
+ }
+};
+
+template <class T>
+void test() {
+ using A = std::atomic<T>;
+ static_assert(std::is_same<typename A::value_type, T>::value, "");
+ test_atomic<T>();
}
struct TriviallyCopyable {
- int i_;
+ int i_;
};
-struct WeirdTriviallyCopyable
-{
- char i, j, k; /* the 3 chars of doom */
+struct WeirdTriviallyCopyable {
+ char i, j, k; /* the 3 chars of doom */
};
-struct PaddedTriviallyCopyable
-{
- char i; int j; /* probably lock-free? */
+struct PaddedTriviallyCopyable {
+ char i;
+ int j; /* probably lock-free? */
};
-struct LargeTriviallyCopyable
-{
- int i, j[127]; /* decidedly not lock-free */
+struct LargeTriviallyCopyable {
+ int i, j[127]; /* decidedly not lock-free */
};
-int main(int, char**)
-{
- test<bool> ();
- test<char> ();
- test<signed char> ();
- test<unsigned char> ();
- test<short> ();
- test<unsigned short> ();
- test<int> ();
- test<unsigned int> ();
- test<long> ();
- test<unsigned long> ();
- test<long long> ();
- test<unsigned long long> ();
+int main(int, char**) {
+ test<bool>();
+ test<char>();
+ test<signed char>();
+ test<unsigned char>();
+ test<short>();
+ test<unsigned short>();
+ test<int>();
+ test<unsigned int>();
+ test<long>();
+ test<unsigned long>();
+ test<long long>();
+ test<unsigned long long>();
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
- test<char8_t> ();
+ test<char8_t>();
#endif
- test<char16_t> ();
- test<char32_t> ();
+ test<char16_t>();
+ test<char32_t>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test<wchar_t> ();
+ test<wchar_t>();
#endif
- test<std::int_least8_t> ();
- test<std::uint_least8_t> ();
- test<std::int_least16_t> ();
- test<std::uint_least16_t> ();
- test<std::int_least32_t> ();
- test<std::uint_least32_t> ();
- test<std::int_least64_t> ();
- test<std::uint_least64_t> ();
-
- test<std::int_fast8_t> ();
- test<std::uint_fast8_t> ();
- test<std::int_fast16_t> ();
- test<std::uint_fast16_t> ();
- test<std::int_fast32_t> ();
- test<std::uint_fast32_t> ();
- test<std::int_fast64_t> ();
- test<std::uint_fast64_t> ();
-
- test< std::int8_t> ();
- test<std::uint8_t> ();
- test< std::int16_t> ();
- test<std::uint16_t> ();
- test< std::int32_t> ();
- test<std::uint32_t> ();
- test< std::int64_t> ();
- test<std::uint64_t> ();
-
- test<std::intptr_t> ();
- test<std::uintptr_t> ();
- test<std::size_t> ();
- test<std::ptr
diff _t> ();
- test<std::intmax_t> ();
- test<std::uintmax_t> ();
-
- test<std::uintmax_t> ();
- test<std::uintmax_t> ();
-
- test<TriviallyCopyable>();
- test<PaddedTriviallyCopyable>();
+ test<std::int_least8_t>();
+ test<std::uint_least8_t>();
+ test<std::int_least16_t>();
+ test<std::uint_least16_t>();
+ test<std::int_least32_t>();
+ test<std::uint_least32_t>();
+ test<std::int_least64_t>();
+ test<std::uint_least64_t>();
+
+ test<std::int_fast8_t>();
+ test<std::uint_fast8_t>();
+ test<std::int_fast16_t>();
+ test<std::uint_fast16_t>();
+ test<std::int_fast32_t>();
+ test<std::uint_fast32_t>();
+ test<std::int_fast64_t>();
+ test<std::uint_fast64_t>();
+
+ test< std::int8_t>();
+ test<std::uint8_t>();
+ test< std::int16_t>();
+ test<std::uint16_t>();
+ test< std::int32_t>();
+ test<std::uint32_t>();
+ test< std::int64_t>();
+ test<std::uint64_t>();
+
+ test<std::intptr_t>();
+ test<std::uintptr_t>();
+ test<std::size_t>();
+ test<std::ptr
diff _t>();
+ test<std::intmax_t>();
+ test<std::uintmax_t>();
+
+ test<std::uintmax_t>();
+ test<std::uintmax_t>();
+
+ test<void (*)(int)>();
+ test<void*>();
+ test<const void*>();
+ test<int*>();
+ test<const int*>();
+
+ test<TriviallyCopyable>();
+ test<PaddedTriviallyCopyable>();
#ifndef __APPLE__ // Apple doesn't ship libatomic
- /*
+ /*
These aren't going to be lock-free,
so some libatomic.a is necessary.
*/
- test<WeirdTriviallyCopyable>();
- test<LargeTriviallyCopyable>();
+ test<WeirdTriviallyCopyable>();
+ test<LargeTriviallyCopyable>();
#endif
#ifndef TEST_HAS_NO_THREADS
- test<std::thread::id>();
+ test<std::thread::id>();
#endif
- test<std::chrono::nanoseconds>();
- test<float>();
+ test<std::chrono::nanoseconds>();
+ test<float>();
#if TEST_STD_VER >= 20
- test<std::atomic_signed_lock_free::value_type>();
- static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>);
- static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>);
+ test<std::atomic_signed_lock_free::value_type>();
+ static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>);
+ static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>);
- test<std::atomic_unsigned_lock_free::value_type>();
- static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>);
- static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>);
+ test<std::atomic_unsigned_lock_free::value_type>();
+ static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>);
+ static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>);
/*
test<std::shared_ptr<int>>();
*/
#endif
- return 0;
+ return 0;
}
More information about the libcxx-commits
mailing list