From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D259C384AB45; Wed, 15 May 2024 17:16:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D259C384AB45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715793400; bh=PrMyXuAYuL+cWyk2CcuKnLqlOt0S9JIXzNzbGNsS8zw=; h=From:To:Subject:Date:From; b=PYrik/jEcVr7720UR2y+QFTTTy4IEWl42xfg4k0lU3fVL3cO9GYuw4AbNjJITO+pn 9rzh3KEydpCcvYAZ0N5Lye5HxoAS1Wrvnp2m83ZVYXL0667tPMll2X3bwrHqK6MuQP l+LEOJ+h1bq0EIev83k+GNpDQS0KpgtROBsiFZsg= From: "luigighiron at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/115109] New: Incorrect type of enumeration constant in redeclaration of enumeration constant (C23) Date: Wed, 15 May 2024 17:16:40 +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: 14.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=3D115109 Bug ID: 115109 Summary: Incorrect type of enumeration constant in redeclaration of enumeration constant (C23) Product: gcc Version: 14.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 the following code: static_assert(INT_WIDTH<42&&LONG_WIDTH>=3D42); enum E{a=3D1UL<<40,b=3D1}; enum E{a=3D1ULL<<40,b=3D_Generic(a,unsigned long:1,default:2)}; The static_assert is there to document the assumptions that should make this code valid. Here is the relevant part of the standard: > During the processing of each enumeration constant in the enumerator list, > the type of the enumeration constant shall be: >=20 > - the previously declared type, if it is a redeclaration of the same > enumeration constant; or, >=20 > - the enumerated type, for an enumeration with fixed underlying type; or, >=20 > - int, if there are no previous enumeration constants in the enumerator l= ist > and no explicit =3D with a defining integer constant expression; or, >=20 > - int, if given explicitly with =3D and the value of the integer constant > expression is representable by an int; or, >=20 > - the type of the integer constant expression, if given explicitly with = =3D and > if the value of the integer constant expression is not representable by= int; > or, >=20 > ... Section 6.7.3.3 "Enumeration specifiers" Paragraph 12 N3220 The types of the enumeration constants 'a' and 'b' in the first enumeration specifier should be unsigned long and int, respectively. Then in the second enumeration declaration, they should have the same types as the first enumeration declaration because of the first item in the list in the above quote. GCC does not seem to follow this and makes the type of the enumerati= on constant 'a' unsigned long long because the type of the expression is unsig= ned long long.=