aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-06-16 22:34:55 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-06-16 22:34:55 +0100
commite40b11a91cb345db1324c3cb8f75b01e28056693 (patch)
tree31db062e48f4fa492a5f246413308332f5316ca7
parentcc799df98f6eaf73763a069f7854e490a0416573 (diff)
downloadgcc-e40b11a91cb345db1324c3cb8f75b01e28056693.zip
gcc-e40b11a91cb345db1324c3cb8f75b01e28056693.tar.gz
gcc-e40b11a91cb345db1324c3cb8f75b01e28056693.tar.bz2
libstdc++: Strip cv-qualifiers in std::atomic<FP> (PR 95282)
This improves the previous fix for PR 95282, and extends it to also apply to the exchange function (which has a similar problem and would become ill-formed with my proposed fix for PR 95378). PR libstdc++/95282 * include/bits/atomic_base.h (__atomic_impl::load): Use the _Val alias instead of deducing _Tp as an unqualified type. (__atomic_impl::exchange): Use the _Val alias to remove volatile from the reinterpret_cast result type.
-rw-r--r--libstdc++-v3/include/bits/atomic_base.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index ebcfeb4..015acef 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -870,21 +870,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ __atomic_store(__ptr, std::__addressof(__t), int(__m)); }
template<typename _Tp>
- _GLIBCXX_ALWAYS_INLINE _Tp
- load(const volatile _Tp* __ptr, memory_order __m) noexcept
+ _GLIBCXX_ALWAYS_INLINE _Val<_Tp>
+ load(const _Tp* __ptr, memory_order __m) noexcept
{
alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
- _Tp* __dest = reinterpret_cast<_Tp*>(__buf);
+ auto* __dest = reinterpret_cast<_Val<_Tp>*>(__buf);
__atomic_load(__ptr, __dest, int(__m));
return *__dest;
}
template<typename _Tp>
- _GLIBCXX_ALWAYS_INLINE _Tp
+ _GLIBCXX_ALWAYS_INLINE _Val<_Tp>
exchange(_Tp* __ptr, _Val<_Tp> __desired, memory_order __m) noexcept
{
alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
- _Tp* __dest = reinterpret_cast<_Tp*>(__buf);
+ auto* __dest = reinterpret_cast<_Val<_Tp>*>(__buf);
__atomic_exchange(__ptr, std::__addressof(__desired), __dest, int(__m));
return *__dest;
}