Why is an explicit type conversion whose type-specifier is void and the initializer is non-empty braced-init-list invalid?

Viewed 61
int main(){
   void{1,2}; // #1
}

#1 is complained be invalid by both GCC and Clang. However, from the point of grammar, it may be valid.
expr.post#general-1

simple-type-specifier braced-init-list

The grammar does not restrict what the braced-init-list should be. From the point of the relevant rule, it also does not have any statement for this case
expr.type.conv#2

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.

From the point of definition of the initialization, it states that
dcl.init#general-14

The initialization that occurs

  • in a functional notation type conversion

Since a prvalue of type void performs no initialization and does not have a result object, hence the whole dcl.init.list#3 is not suitable here

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

The case cannot even be caught by dcl.init.list#3.12

Otherwise, the program is ill-formed.

So, I wonder Is any rule states that void{1,2} should be considered ill-formed?

0 Answers
Related