https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115566
Bug ID: 115566 Summary: Arrays of character type initialized with parenthesized string literals shouldn't be diagnosed with -pedantic (at least in C23) Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: luigighiron at gmail dot com Target Milestone: --- GCC does not accept initializing an array of character type with a parenthesized string literal when compiling with -pedantic, for example: char x[]=("abc"); This causes a warning, or an error with -pedantic-errors. This should be valid because of the following: > A parenthesized expression is a primary expression. Its type, value, and > semantics are identical to those of the unparenthesized expression. Section 6.5.2 "Primary Expressions" Paragraph 6 N3220 The semantics of the expression ("abc") are equivalent to those of "abc" so this declaration should be valid. The wording in prior versions was not so clear that the semantics are the same, but I assume the intent was still to allow this. Clang accepts this, even with -std=c89 -pedantic. MSVC accepts this with all warnings enabled. Interestingly, GCC correctly accepts using _Generic expressions which have a string literal as the selected branch to be used in initialization of an array of character type: char x[]=_Generic(0,int:"abc"); Parenthesizing the _Generic expression or the string literal itself causes GCC to create a warning again. Multiple nested _Generic expressions works as well.