-
Notifications
You must be signed in to change notification settings - Fork 53
Closed
Labels
issue-resolved问题已解决问题已解决
Description
std::atomic<T*>小节
operator+=
和operator-=
:以原子方式增加或减少指针的值。返回操作前的指针值
存在错误。以libstdc++为例,std::__atomic_base<_Tp*>的operator-=调用函数为sub_fetch
而非fetch_sub
:
__int_type
operator-=(__int_type __i) volatile noexcept
{ return __atomic_sub_fetch(&_M_i, __i, int(memory_order_seq_cst)); }
故返回的是操作后的指针值,这也符合+=/-=的语义。在后续示例代码中代码正确,但注释也要相应修改:
// p 减 1,并返回原始值
x = (p -= 1);
assert(x == &array[1]);
assert(p.load() == &array[1]);
Metadata
Metadata
Assignees
Labels
issue-resolved问题已解决问题已解决