From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D2D073890431; Thu, 20 Jun 2024 20:50:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2D073890431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718916607; bh=126Q6MoxxT4HzRk/yLkrvlt2qYgscgssbYZKUCIR+HQ=; h=From:To:Subject:Date:From; b=qPPiCTnPJcqzo62laGwEsIupWsCknL72NWoI3cPo4csJJepsDpASK2LR0LieEQZ6G J11bGYG98BMbJPf/0DNEW6N7mZ24b3raH5TEIR2JNlNBRiZqg1sNJ6XLPDluZImWJj eapjGuTxiQslMKVm56hvaQQ3wN//ooBzEI7+fOuw= From: "luigighiron at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/115566] New: Arrays of character type initialized with parenthesized string literals shouldn't be diagnosed with -pedantic (at least in C23) Date: Thu, 20 Jun 2024 20:50:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: luigighiron at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115566 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[]=3D("abc"); This causes a warning, or an error with -pedantic-errors. This should be va= lid 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=3Dc89 -pedantic. MSVC accept= s this with all warnings enabled. Interestingly, GCC correctly accepts using _Gene= ric expressions which have a string literal as the selected branch to be used in initialization of an array of character type: char x[]=3D_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 we= ll.=