Skip to content

CWG3102 [basic.fundamental] Allow expressions of type void in a requires-expression #788

@eisenwave

Description

@eisenwave

Reference (section label): [basic.fundamental] paragraph 15

Issue description

The expression requires { void(); } is ill-formed, but no compiler implements this behavior (https://godbolt.org/z/Eha5vz4oe). Disallowing expression of type cv void here was never motivated and appears to be an oversight.

Furthermore, (void()) is well-formed according to [expr.prim.paren], but is not listed as a bullet, and listing it may provide editorial clarity.

Suggested resolution

Change [basic.fundamental] paragraph 15 as follows:

 A type cv void is an incomplete type that cannot be completed;
 such a type has an empty set of values.
 It is used as the return type for functions that do not return a value.
 An expression of type cv void shall be used only as 
 - an expression statement ([stmt.expr]),
 - the expression in a return statement ([stmt.return])
   for a function with return type cv void
 - an operand of a comma expression ([expr.comma])
+- the operand of a parenthesized expression ([expr.prim.paren])
+- a requirement in a requires expression ([expr.prim.req.general])
 - the second or third operand of ?: ([expr.cond])
 - the operand of a typeid expression ([expr.typeid])
 - the operand of a noexcept operator ([expr.unary.noexcept])
 - the operand of a decltype specifier ([dcl.type.decltype]), or
 - the operand of an explicit conversion to type
   cv void ([expr.type.conv], [expr.static.cast], [expr.cast])

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