Skip to content

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

Closed
@xmh0511

Description

@xmh0511

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

Dani-Hub commented on Aug 26, 2023

@Dani-Hub
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

jensmaurer commented on Aug 26, 2023

@jensmaurer
Member

Patch welcome to express the preconditions as a positive list.

Dani-Hub

Dani-Hub commented on Aug 26, 2023

@Dani-Hub
Member

I will work on that

Dani-Hub

Dani-Hub commented on Aug 26, 2023

@Dani-Hub
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Dani-Hub@xmh0511@jensmaurer

      Issue actions

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