Skip to content

Commit 0fd8850

Browse files
committed
Fix atomic smart pointers with array elements
Fix atomic smart pointers with array elements by making the internal type match that of [weak|shared]_ptr::element_type by removing the extent of the arrays.
1 parent 975ac24 commit 0fd8850

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

Diff for: stl/inc/memory

+14-13
Original file line numberDiff line numberDiff line change
@@ -3812,9 +3812,10 @@ class alignas(2 * sizeof(void*)) _Atomic_ptr_base {
38123812
protected:
38133813
constexpr _Atomic_ptr_base() noexcept = default;
38143814

3815-
_Atomic_ptr_base(_Ty* const _Px, _Ref_count_base* const _Ref) noexcept : _Ptr(_Px), _Repptr(_Ref) {}
3815+
_Atomic_ptr_base(remove_extent_t<_Ty>* const _Px, _Ref_count_base* const _Ref) noexcept
3816+
: _Ptr(_Px), _Repptr(_Ref) {}
38163817

3817-
void _Wait(_Ty* _Old, memory_order) const noexcept {
3818+
void _Wait(remove_extent_t<_Ty>* _Old, memory_order) const noexcept {
38183819
for (;;) {
38193820
auto _Rep = _Repptr._Lock_and_load();
38203821
bool _Equal = _Ptr.load(memory_order_relaxed) == _Old;
@@ -3834,7 +3835,7 @@ protected:
38343835
_Ptr.notify_all();
38353836
}
38363837

3837-
atomic<_Ty*> _Ptr{nullptr};
3838+
atomic<remove_extent_t<_Ty>*> _Ptr{nullptr};
38383839
mutable _Locked_pointer<_Ref_count_base> _Repptr;
38393840
};
38403841

@@ -3854,9 +3855,9 @@ public:
38543855

38553856
void store(shared_ptr<_Ty> _Value, const memory_order _Order = memory_order_seq_cst) noexcept {
38563857
_Check_store_memory_order(_Order);
3857-
const auto _Rep = this->_Repptr._Lock_and_load();
3858-
_Ty* const _Tmp = _Value._Ptr;
3859-
_Value._Ptr = this->_Ptr.load(memory_order_relaxed);
3858+
const auto _Rep = this->_Repptr._Lock_and_load();
3859+
remove_extent_t<_Ty>* const _Tmp = _Value._Ptr;
3860+
_Value._Ptr = this->_Ptr.load(memory_order_relaxed);
38603861
this->_Ptr.store(_Tmp, memory_order_relaxed);
38613862
this->_Repptr._Store_and_unlock(_Value._Rep);
38623863
_Value._Rep = _Rep;
@@ -3909,8 +3910,8 @@ public:
39093910
_Check_memory_order(_Order);
39103911
auto _Rep = this->_Repptr._Lock_and_load();
39113912
if (this->_Ptr.load(memory_order_relaxed) == _Expected._Ptr && _Rep == _Expected._Rep) {
3912-
_Ty* const _Tmp = _Desired._Ptr;
3913-
_Desired._Ptr = this->_Ptr.load(memory_order_relaxed);
3913+
remove_extent_t<_Ty>* const _Tmp = _Desired._Ptr;
3914+
_Desired._Ptr = this->_Ptr.load(memory_order_relaxed);
39143915
this->_Ptr.store(_Tmp, memory_order_relaxed);
39153916
_STD swap(_Rep, _Desired._Rep);
39163917
this->_Repptr._Store_and_unlock(_Rep);
@@ -3971,9 +3972,9 @@ public:
39713972

39723973
void store(weak_ptr<_Ty> _Value, const memory_order _Order = memory_order_seq_cst) noexcept {
39733974
_Check_store_memory_order(_Order);
3974-
const auto _Rep = this->_Repptr._Lock_and_load();
3975-
_Ty* const _Tmp = _Value._Ptr;
3976-
_Value._Ptr = this->_Ptr.load(memory_order_relaxed);
3975+
const auto _Rep = this->_Repptr._Lock_and_load();
3976+
remove_extent_t<_Ty>* const _Tmp = _Value._Ptr;
3977+
_Value._Ptr = this->_Ptr.load(memory_order_relaxed);
39773978
this->_Ptr.store(_Tmp, memory_order_relaxed);
39783979
this->_Repptr._Store_and_unlock(_Value._Rep);
39793980
_Value._Rep = _Rep;
@@ -4026,8 +4027,8 @@ public:
40264027
_Check_memory_order(_Order);
40274028
auto _Rep = this->_Repptr._Lock_and_load();
40284029
if (this->_Ptr.load(memory_order_relaxed) == _Expected._Ptr && _Rep == _Expected._Rep) {
4029-
_Ty* const _Tmp = _Desired._Ptr;
4030-
_Desired._Ptr = this->_Ptr.load(memory_order_relaxed);
4030+
remove_extent_t<_Ty>* const _Tmp = _Desired._Ptr;
4031+
_Desired._Ptr = this->_Ptr.load(memory_order_relaxed);
40314032
this->_Ptr.store(_Tmp, memory_order_relaxed);
40324033
_STD swap(_Rep, _Desired._Rep);
40334034
this->_Repptr._Store_and_unlock(_Rep);

0 commit comments

Comments
 (0)