Skip to content

[expr.const.core] Blocking the thread of execution should not be a core constant expression #1002

Description

@eisenwave

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

Reference (section label): [expr.const.core]

Prior discussion: cplusplus/draft#9298

Issue description

[atomics.types.operations] specifies that std::atomic<T>::wait is constexpr and that it blocks the thread if the given value is equal to the current value of the object. Other atomic waiting operations ([atomics.wait]) can also block, such as std::atomic_flag::wait.

P3309R3 argues that blocking the thread is not a constant expression because it exceeds implementation limits, but it is unclear which (if any) implementation limits are exceeded by blocking. One might also argue that blocking the thread violates the forward progress guarantee ([intro.progress]), which is undefined behavior and thus not a core constant expression, but this explanation is contrived.

Suggested resolution

Add a bullet to [expr.const.core] paragraph 2:

 An expression E is a core constant expression unless the evaluation of E,
 following the rules of the abstract machine ([intro.execution]),
 would evaluate one of the following:
   - ...
   - an invocation of the va_arg macro ([cstdarg.syn]);
+  - an operation that blocks the thread of execution ([defns.block]);
   - a non-constant library call ([defns.nonconst.libcall]); or
   - ...

Activity

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

      No branches or pull requests

      Issue actions