mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
libstdc++: Fix test FAIL due to -Wpointer-arith
This fixes a FAIL due to a -Wpointer-arith warning when testing with c++11 or c++14 dialects. As an extension our std::atomic<void*> supports pointer arithmetic in C++11 and C++14, but due to the system header changes there is now a warning about it. The warning seems reasonable, so rather than suppress it we should make the test expect it. While looking into this I decided to simplify some of the code related to atomic<T*> arithmetic. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (__atomic_base<T*>::_M_type_size): Replace overloaded functions with static _S_type_size. * include/std/atomic (atomic<T*>): Use is_object_v instead of is_object. * testsuite/29_atomics/atomic/operators/pointer_partial_void.cc: Add dg-warning for -Wpointer-arith warning.
This commit is contained in:
parent
0ff49a5c1d
commit
500046d178
@ -687,12 +687,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
|
||||
__pointer_type _M_p _GLIBCXX20_INIT(nullptr);
|
||||
|
||||
// Factored out to facilitate explicit specialization.
|
||||
constexpr ptrdiff_t
|
||||
_M_type_size(ptrdiff_t __d) const { return __d * sizeof(_PTp); }
|
||||
|
||||
constexpr ptrdiff_t
|
||||
_M_type_size(ptrdiff_t __d) const volatile { return __d * sizeof(_PTp); }
|
||||
static constexpr ptrdiff_t
|
||||
_S_type_size(ptrdiff_t __d)
|
||||
{ return __d * sizeof(_PTp); }
|
||||
|
||||
public:
|
||||
__atomic_base() noexcept = default;
|
||||
@ -742,42 +739,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
|
||||
__pointer_type
|
||||
operator++() noexcept
|
||||
{ return __atomic_add_fetch(&_M_p, _M_type_size(1),
|
||||
{ return __atomic_add_fetch(&_M_p, _S_type_size(1),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator++() volatile noexcept
|
||||
{ return __atomic_add_fetch(&_M_p, _M_type_size(1),
|
||||
{ return __atomic_add_fetch(&_M_p, _S_type_size(1),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator--() noexcept
|
||||
{ return __atomic_sub_fetch(&_M_p, _M_type_size(1),
|
||||
{ return __atomic_sub_fetch(&_M_p, _S_type_size(1),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator--() volatile noexcept
|
||||
{ return __atomic_sub_fetch(&_M_p, _M_type_size(1),
|
||||
{ return __atomic_sub_fetch(&_M_p, _S_type_size(1),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator+=(ptrdiff_t __d) noexcept
|
||||
{ return __atomic_add_fetch(&_M_p, _M_type_size(__d),
|
||||
{ return __atomic_add_fetch(&_M_p, _S_type_size(__d),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator+=(ptrdiff_t __d) volatile noexcept
|
||||
{ return __atomic_add_fetch(&_M_p, _M_type_size(__d),
|
||||
{ return __atomic_add_fetch(&_M_p, _S_type_size(__d),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator-=(ptrdiff_t __d) noexcept
|
||||
{ return __atomic_sub_fetch(&_M_p, _M_type_size(__d),
|
||||
{ return __atomic_sub_fetch(&_M_p, _S_type_size(__d),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
__pointer_type
|
||||
operator-=(ptrdiff_t __d) volatile noexcept
|
||||
{ return __atomic_sub_fetch(&_M_p, _M_type_size(__d),
|
||||
{ return __atomic_sub_fetch(&_M_p, _S_type_size(__d),
|
||||
int(memory_order_seq_cst)); }
|
||||
|
||||
bool
|
||||
@ -932,22 +929,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
_GLIBCXX_ALWAYS_INLINE __pointer_type
|
||||
fetch_add(ptrdiff_t __d,
|
||||
memory_order __m = memory_order_seq_cst) noexcept
|
||||
{ return __atomic_fetch_add(&_M_p, _M_type_size(__d), int(__m)); }
|
||||
{ return __atomic_fetch_add(&_M_p, _S_type_size(__d), int(__m)); }
|
||||
|
||||
_GLIBCXX_ALWAYS_INLINE __pointer_type
|
||||
fetch_add(ptrdiff_t __d,
|
||||
memory_order __m = memory_order_seq_cst) volatile noexcept
|
||||
{ return __atomic_fetch_add(&_M_p, _M_type_size(__d), int(__m)); }
|
||||
{ return __atomic_fetch_add(&_M_p, _S_type_size(__d), int(__m)); }
|
||||
|
||||
_GLIBCXX_ALWAYS_INLINE __pointer_type
|
||||
fetch_sub(ptrdiff_t __d,
|
||||
memory_order __m = memory_order_seq_cst) noexcept
|
||||
{ return __atomic_fetch_sub(&_M_p, _M_type_size(__d), int(__m)); }
|
||||
{ return __atomic_fetch_sub(&_M_p, _S_type_size(__d), int(__m)); }
|
||||
|
||||
_GLIBCXX_ALWAYS_INLINE __pointer_type
|
||||
fetch_sub(ptrdiff_t __d,
|
||||
memory_order __m = memory_order_seq_cst) volatile noexcept
|
||||
{ return __atomic_fetch_sub(&_M_p, _M_type_size(__d), int(__m)); }
|
||||
{ return __atomic_fetch_sub(&_M_p, _S_type_size(__d), int(__m)); }
|
||||
};
|
||||
|
||||
namespace __atomic_impl
|
||||
|
@ -453,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator++(int) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b++;
|
||||
}
|
||||
@ -462,7 +462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator++(int) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b++;
|
||||
}
|
||||
@ -471,7 +471,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator--(int) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b--;
|
||||
}
|
||||
@ -480,7 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator--(int) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b--;
|
||||
}
|
||||
@ -489,7 +489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator++() noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return ++_M_b;
|
||||
}
|
||||
@ -498,7 +498,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator++() volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return ++_M_b;
|
||||
}
|
||||
@ -507,7 +507,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator--() noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return --_M_b;
|
||||
}
|
||||
@ -516,7 +516,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator--() volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return --_M_b;
|
||||
}
|
||||
@ -525,7 +525,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator+=(ptrdiff_t __d) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.operator+=(__d);
|
||||
}
|
||||
@ -534,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator+=(ptrdiff_t __d) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.operator+=(__d);
|
||||
}
|
||||
@ -543,7 +543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator-=(ptrdiff_t __d) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.operator-=(__d);
|
||||
}
|
||||
@ -552,7 +552,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
operator-=(ptrdiff_t __d) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.operator-=(__d);
|
||||
}
|
||||
@ -673,7 +673,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
memory_order __m = memory_order_seq_cst) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.fetch_add(__d, __m);
|
||||
}
|
||||
@ -683,7 +683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
memory_order __m = memory_order_seq_cst) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.fetch_add(__d, __m);
|
||||
}
|
||||
@ -693,7 +693,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
memory_order __m = memory_order_seq_cst) noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.fetch_sub(__d, __m);
|
||||
}
|
||||
@ -703,7 +703,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
memory_order __m = memory_order_seq_cst) volatile noexcept
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert( is_object<_Tp>::value, "pointer to object type" );
|
||||
static_assert( is_object_v<_Tp>, "pointer to object type" );
|
||||
#endif
|
||||
return _M_b.fetch_sub(__d, __m);
|
||||
}
|
||||
|
@ -68,3 +68,4 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
// { dg-warning "invalid application of 'sizeof' to a void type" "" { target *-*-* } 0 }
|
||||
|
Loading…
Reference in New Issue
Block a user