#include <iostream>
int main(){
using type = int[2];
static_cast<type>(type{1,2}); //#1
}
Clang and GCC both complain that #1 is ill-formed, and give weird diagnoses.
Clang reports
static_cast from 'int *' to 'type' (aka 'int [2]') is not allowed
GCC reports
invalid 'static_cast' from type 'type' {aka 'int [2]'} to type 'type' {aka 'int [2]'}
However, as per expr.static.cast#4
An expression E can be explicitly converted to a type T if there is an implicit conversion sequence ([over.best.ics]) from E to T
Isn't that converts a type to the same type be called identity conversion?
over.best.ics#general-8
If no conversions are required to match an argument to a parameter type, the implicit conversion sequence is the standard conversion sequence consisting of the identity conversion ([over.ics.scs]).
I think a crucial rule here is
The sequence of conversions is an implicit conversion as defined in [conv], which means it is governed by the rules for initialization of an object or reference by a single expression ([dcl.init], [dcl.init.ref]).
That means, assume a result object would be t which will be initialized by the prvalue.
type t = type{1,2}; // #2
#2 is also rejected by Clang and GCC. However, such a case should be caught by dcl.init.general#15.9
Otherwise, the initial value of the object being initialized is the (possibly converted) value of the initializer expression. A standard conversion sequence ([conv]) will be used, if necessary, to convert the initializer expression to the cv-unqualified version of the destination type; no user-defined conversions are considered. If the conversion cannot be done, the initialization is ill-formed. When initializing a bit-field with a value that it cannot represent, the resulting value of the bit-field is implementation-defined.
According to basic.lval#1.2
A prvalue is an expression whose evaluation initializes an object or computes the value of an operand of an operator, as specified by the context in which it appears, or an expression that has type cv void.
In which case, Isn't that a prvalue of type type cannot initialize the result object?
Clang assumes that array-to-pointer conversion applies to the operand. However, such a conversion is only permitted if the bullet steps into expr.static.cast#8. In other words, the conversion should not apply here for the operand in bullet 4.
GCC gives a more nonreasonable diagnosis. I wonder why the explicit conversion is forbidden by Clang and GCC?