Skip to content

A corner case for an explicit type conversion whose type-specifier is void and the initializer is non-empty braced-init-list #4626

@xmh0511

Description

@xmh0511
int main(){
   void{1,2}; // #1
}

This corner case seems to be ignored by the standard, there's no rule in the current draft that criticizes the example as invalid.

First, the case is permitted by the grammar

simple-type-specifier braced-init-list
The grammar does not restrict what the braced-init-list should be(must be empty or not).

From the perspective of [expr.type.conv#2], it does not cover this case

If the initializer is a parenthesized single expression, the type conversion expression is equivalent to the corresponding cast expression. Otherwise, if the type is cv void and the initializer is () or {} (after pack expansion, if any), the expression is a prvalue of type void that performs no initialization. Otherwise, the expression is a prvalue of the specified type whose result object is direct-initialized with the initializer. If the initializer is a parenthesized optional expression-list, the specified type shall not be an array type.

According to [dcl.init#general-14]

The initialization that occurs

  • in a functional notation type conversion

is called direct-initialization.

So, we will inspect [dcl.init.list] for this case. Meanwhile, [dcl.init.list#3.12] is also not suitable for this case

Otherwise, the program is ill-formed.

Since its condition is:

List-initialization of an object or reference of type T is defined as follows:

A prvalue of type void does not result in "initialization". So, it arguably says that such a corner case is not covered by the standard.

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