2929# include < thread>
3030#endif
3131
32- template <class A , bool Integral>
32+ // detect existence of the difference_type member type
33+ template <class ...>
34+ using myvoid_t = void ;
35+ template <typename T, typename = void >
36+ struct has_difference_type : std::false_type {};
37+ template <typename T>
38+ struct has_difference_type <T, myvoid_t <typename T::difference_type> > : std::true_type {};
39+
40+ template <class A , bool IntegralOrFloating, bool Pointer>
3341struct test_atomic {
3442 test_atomic () {
43+ static_assert (!IntegralOrFloating || !Pointer, " " );
3544 A a;
3645 (void )a;
3746#if TEST_STD_VER >= 17
3847 static_assert ((std::is_same_v<typename A::value_type, decltype (a.load ())>), " " );
48+ static_assert (!has_difference_type<A>::value, " " );
3949#endif
4050 }
4151};
4252
4353template <class A >
44- struct test_atomic <A, true > {
54+ struct test_atomic <A, true , false > {
4555 test_atomic () {
4656 A a;
4757 (void )a;
@@ -53,7 +63,7 @@ struct test_atomic<A, true> {
5363};
5464
5565template <class A >
56- struct test_atomic <A* , false > {
66+ struct test_atomic <A, false , true > {
5767 test_atomic () {
5868 A a;
5969 (void )a;
@@ -70,7 +80,10 @@ void test() {
7080#if TEST_STD_VER >= 17
7181 static_assert ((std::is_same_v<typename A::value_type, T>), " " );
7282#endif
73- test_atomic<A, std::is_integral<T>::value && !std::is_same<T, bool >::value>();
83+ constexpr bool IntegralOrFloating =
84+ (std::is_integral<T>::value && !std::is_same<T, bool >::value) || std::is_floating_point<T>::value;
85+ constexpr bool Pointer = std::is_pointer<T>::value;
86+ test_atomic<A, IntegralOrFloating, Pointer>();
7487}
7588
7689struct TriviallyCopyable {
@@ -149,6 +162,11 @@ int main(int, char**) {
149162 test<std::uintmax_t >();
150163 test<std::uintmax_t >();
151164
165+ test<void *>();
166+ test<const void *>();
167+ test<int *>();
168+ test<const int *>();
169+
152170 test<TriviallyCopyable>();
153171 test<PaddedTriviallyCopyable>();
154172#ifndef __APPLE__ // Apple doesn't ship libatomic
0 commit comments