Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xmh0511 opened this issue Aug 25, 2023 · 4 comments · Fixed by #6519
Closed

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 25, 2023

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.

@Dani-Hub
Copy link
Member

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
Copy link
Member

Patch welcome to express the preconditions as a positive list.

@Dani-Hub
Copy link
Member

I will work on that

@Dani-Hub
Copy link
Member

There exists now PULL request #6518.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants