[libcxx-commits] [libcxx] [libc++] std::atomic primary template should not have a difference type member type (PR #123236)

Damien L-G via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 16 12:19:33 PST 2025


================
@@ -29,163 +29,173 @@
 #  include <thread>
 #endif
 
-template <class A, bool Integral>
-struct test_atomic
-{
-    test_atomic()
-    {
-        A a; (void)a;
+// detect existence of the difference_type member type
+template <class...>
+using myvoid_t = void;
+template <typename T, typename = void>
+struct has_difference_type : std::false_type {};
+template <typename T>
+struct has_difference_type<T, myvoid_t<typename T::difference_type> > : std::true_type {};
+
+template <class A, bool IntegralOrFloating, bool Pointer>
+struct test_atomic {
+  test_atomic() {
+    static_assert(!IntegralOrFloating || !Pointer, "");
+    A a;
+    (void)a;
 #if TEST_STD_VER >= 17
     static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), "");
+    static_assert(!has_difference_type<A>::value, "");
 #endif
-    }
+  }
 };
 
 template <class A>
-struct test_atomic<A, true>
-{
-    test_atomic()
-    {
-        A a; (void)a;
+struct test_atomic<A, true, 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::value_type, typename A::difference_type>), "");
 #endif
-    }
+  }
 };
 
 template <class A>
-struct test_atomic<A*, false>
----------------
dalg24 wrote:

This would never occur since we were instantiating with `A = std::atomic<T>`

https://github.com/llvm/llvm-project/pull/123236


More information about the libcxx-commits mailing list