From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6E9D53853809; Wed, 26 Oct 2022 07:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E9D53853809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666770325; bh=b4OYmpIKdKGk7vrp47sd5OhorsavSvVMtfcPakh26/c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sinA2m6B33TALK+g/cOxHRZKpFUO43+iltkqBhxJo14MJdti+1xPuxJJZZXnWauml tLYbTvEUTgnZRawKmGghyio275WTOyP48ilwgORnSIL72o6mEgeIpXjL/0ucUY7d/W 6LlrNnofXJpa1rKF8mK7rY4dVAn2ZyxowlN7J6Wk= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107405] enums can be wrongly long in gcc-13 (in gnu99) Date: Wed, 26 Oct 2022 07:45:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc Message-ID: In-Reply-To: References: 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=3D107405 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #6 from Jakub Jelinek --- (In reply to Jiri Slaby from comment #4) > (In reply to Martin Li=C5=A1ka from comment #3) > > > enum { A =3D 0xffffffff, B =3D 1 << 31, }; > > > int main() { printf("%lx %x %zu\n", A, B, sizeof(B)); } > > >=20 > >=20 > > Apparently, 0xffffffff is treated by the compiler as unsigned int const= ant > > and thus it likely leads to the promotion to a longer interger. >=20 > The problem is that is breaks existing code (which will be barely fixed as > this is clearly gcc-13's bug (or change of behavior at least)). >=20 > Another question is why B is affected by A at all? Also sizeof of that en= um > (if one gives it a name) is 8 with gcc-13. That is not allowed by the > standard, IMO. That is how C++ behaves for years and C2X mandates such behavior too. Enumerators that don't fit into int were a GNU extensions (-pedantic-errors rejects them) and for C have been handled weirdly in the past (only specific enumerators that don't fit had wider types + the enum as whole). enum E { A =3D 0xdeadbeefcafebabeULL, B =3D 2 }; int a =3D sizeof (enum E); int b =3D sizeof (A); int c =3D sizeof (B); above yielded a =3D 8, b =3D 8, c =3D 4 in C, a =3D b =3D c =3D 8 in C++ an= d now in GCC 13 in C too. See https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603809.html for = more details.=