Skip to content

Commit affbb4d

Browse files
dalg24ldionne
andauthored
[libc++] std::atomic primary template should not have a difference_type member type (llvm#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 <[email protected]>
1 parent 45798bd commit affbb4d

File tree

6 files changed

+165
-130
lines changed

6 files changed

+165
-130
lines changed

libcxx/include/__atomic/atomic.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct __atomic_base // false
4040
{
4141
mutable __cxx_atomic_impl<_Tp> __a_;
4242

43+
using value_type = _Tp;
44+
4345
#if _LIBCPP_STD_VER >= 17
4446
static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
4547
#endif
@@ -145,6 +147,8 @@ template <class _Tp>
145147
struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
146148
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>;
147149

150+
using difference_type = typename __base::value_type;
151+
148152
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
149153

150154
_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> > {
229233
template <class _Tp>
230234
struct atomic : public __atomic_base<_Tp> {
231235
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
232-
using value_type = _Tp;
233-
using difference_type = value_type;
234236

235237
#if _LIBCPP_STD_VER >= 20
236238
_LIBCPP_HIDE_FROM_ABI atomic() = default;
@@ -258,8 +260,8 @@ struct atomic : public __atomic_base<_Tp> {
258260
template <class _Tp>
259261
struct atomic<_Tp*> : public __atomic_base<_Tp*> {
260262
using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>;
261-
using value_type = _Tp*;
262-
using difference_type = ptrdiff_t;
263+
264+
using difference_type = ptrdiff_t;
263265

264266
_LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
265267

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
10+
911
// <atomic>
1012

1113
// template <class T>
@@ -63,12 +65,12 @@ struct S {
6365
void member_function_pointer() {
6466
{
6567
volatile std::atomic<void (S::*)(int)> fun;
66-
// expected-error@*:* {{no member named 'fetch_add' in}}
68+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_add'}}
6769
std::atomic_fetch_add(&fun, 0);
6870
}
6971
{
7072
std::atomic<void (S::*)(int)> fun;
71-
// expected-error@*:* {{no member named 'fetch_add' in}}
73+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_add'}}
7274
std::atomic_fetch_add(&fun, 0);
7375
}
7476
}

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
10+
911
// <atomic>
1012

1113
// template <class T>
@@ -66,12 +68,12 @@ struct S {
6668
void member_function_pointer() {
6769
{
6870
volatile std::atomic<void (S::*)(int)> fun;
69-
// expected-error@*:* {{no member named 'fetch_add' in}}
71+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_add_explicit'}}
7072
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed);
7173
}
7274
{
7375
std::atomic<void (S::*)(int)> fun;
74-
// expected-error@*:* {{no member named 'fetch_add' in}}
76+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_add_explicit'}}
7577
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed);
7678
}
7779
}

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
10+
911
// <atomic>
1012

1113
// template <class T>
@@ -63,12 +65,12 @@ struct S {
6365
void member_function_pointer() {
6466
{
6567
volatile std::atomic<void (S::*)(int)> fun;
66-
// expected-error@*:* {{no member named 'fetch_sub' in}}
68+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_sub'}}
6769
std::atomic_fetch_sub(&fun, 0);
6870
}
6971
{
7072
std::atomic<void (S::*)(int)> fun;
71-
// expected-error@*:* {{no member named 'fetch_sub' in}}
73+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_sub'}}
7274
std::atomic_fetch_sub(&fun, 0);
7375
}
7476
}

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
10+
911
// <atomic>
1012

1113
// template <class T>
@@ -66,12 +68,12 @@ struct S {
6668
void member_function_pointer() {
6769
{
6870
volatile std::atomic<void (S::*)(int)> fun;
69-
// expected-error@*:* {{no member named 'fetch_sub' in}}
71+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_sub_explicit'}}
7072
std::atomic_fetch_sub_explicit(&fun, 0, std::memory_order_relaxed);
7173
}
7274
{
7375
std::atomic<void (S::*)(int)> fun;
74-
// expected-error@*:* {{no member named 'fetch_sub' in}}
76+
// expected-error@*:* {{no matching function for call to 'atomic_fetch_sub_explicit'}}
7577
std::atomic_fetch_sub_explicit(&fun, 0, std::memory_order_relaxed);
7678
}
7779
}

0 commit comments

Comments
 (0)