Skip to content

CWG3136 [expr.const] void constant expressions #821

@leni536

Description

@leni536

Full name of submitter (unless configured in github; will be published with the issue): Lénárd Szolnoki

Reference (section label): [expr.const]

Issue description: prvalue void core constant expressions should be constant expressions

A constant expression is either:

  • a glvalue core constant expression E for which
    ...
  • a prvalue core constant expression whose result object ([basic.lval]) satisfies the following constraints
    ...

A prvalue core constant expression of type void has no result object, therefore it's missing from the list. My reading is that such core constant expressions are not constant expressions.

Therefore the following program is ill-formed:

consteval void foo() {}

int main() {
  foo(); // immediate invocation must produce a constant expression
}

GCC, clang and MSVC accept this program (https://godbolt.org/z/Tfjeh3eTo).

In addition, the expression corresponding to a consteval-block-declaration is also a prvalue expression of type void, which "shall be a constant expression" [dcl.pre].

Suggested resolution:

Add the following point under "A constant expression is either:"

  • a prvalue core constant expression of type void.

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