cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[atomics.types.operations] p7 What if the supplied arguments does not denote any enumerator? #398

Closed xmh0511 closed 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

void store(T desired, memory_order order = memory_order::seq_cst) volatile noexcept; void store(T desired, memory_order order = memory_order::seq_cst) noexcept;

Preconditions: The order argument is neither memory_order​::​consume, memory_order​::​acquire, nor memory_order​::​acq_rel.

Consider this case:

#include <atomic>
int main(){
   std::atomic<int> v{0};
   auto invented_ordering = static_cast<std::memory_order>(1024);
   v.store(1,invented_ordering);
}

[enum.dcl.enum] p8 says:

It is possible to define an enumeration that has values not defined by any of its enumerators.

The invented_ordering does not violate the preconditions of store. This may be a LWG issue.

frederick-vs-ja commented 1 year ago

Almost all Preconditions in the whole [atomics] seem to be broken.

jensmaurer commented 1 year ago

The underlying type of std::memory_order might not be able to represent 1024. Maybe it's more prudent to use 7 here.

In any case, this concerns library wording, not core wording, so please report it as an LWG issue.

xmh0511 commented 1 year ago

Almost all Preconditions in the whole [atomics] seem to be broken.

They are not broken because they just list the cases that are not expected, and the converted value does not fall in that cases.