Is this form of initialization valid for arrays?

The following code only compiles to clang AFAIK:

struct A { 
  char x[4]; 
  A():x("bug") { } 

int main()
    char x[4] ("bug");


But according to this gcc bug report it is valid code and has been patched for a later version of GCC (someone should report this to Microsoft as well then.)

Rationale for fixing this error:

§ 8.5 / 13

The form of initialization (using parentheses or =) is usually minor, but does matter when an initializer or object is initialized to a class type; See below. If the entity initialized does not have a class type, the list of expressions in the parenthesized Initializer must be a single expression.

The initialization of arrays char

with string literals is covered in § 8.5.2, which shows only an example using the equal sign. Since this kind of initialization is different from other kinds, is this code valid by the standard?


source to share

All Articles