public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115566] New: Arrays of character type initialized with parenthesized string literals shouldn't be diagnosed with -pedantic (at least in C23)
@ 2024-06-20 20:50 luigighiron at gmail dot com
  2024-06-20 20:57 ` [Bug c/115566] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: luigighiron at gmail dot com @ 2024-06-20 20:50 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-06-22 23:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 20:50 [Bug c/115566] New: Arrays of character type initialized with parenthesized string literals shouldn't be diagnosed with -pedantic (at least in C23) luigighiron at gmail dot com
2024-06-20 20:57 ` [Bug c/115566] " pinskia at gcc dot gnu.org
2024-06-20 21:51 ` pinskia at gcc dot gnu.org
2024-06-20 22:06 ` pinskia at gcc dot gnu.org
2024-06-20 22:17 ` pinskia at gcc dot gnu.org
2024-06-20 22:21 ` pinskia at gcc dot gnu.org
2024-06-20 22:36 ` luigighiron at gmail dot com
2024-06-22 20:20 ` jsm28 at gcc dot gnu.org
2024-06-22 23:49 ` harald at gigawatt dot nl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).