Description
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.
The LWG side asked me to open an editorial post about this issue, even though I have already tried to report an issue on CWG, and the CWG side(cplusplus/CWG#398) has confirmed that this issue should be reported as an LWG issue. The original issue is:
#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 the store, however, this is obviously problematic.
Activity
Dani-Hub commentedon Aug 26, 2023
Before the project editors close this as non-editorially I would like to remind that the corresponding Effects: are defined as follows:
"[...] Memory is affected according to the value of order."
But the standard does not define the meaning of
std::memory_order(1024)
, so to me one can argue that it is possible to solve this editorially by re-expressing the Preconditions: in a positive form listing only the valid values, since the user cannot rely on a concrete effect anyway.jensmaurer commentedon Aug 26, 2023
Patch welcome to express the preconditions as a positive list.
Dani-Hub commentedon Aug 26, 2023
I will work on that
Dani-Hub commentedon Aug 26, 2023
There exists now PULL request #6518.