public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.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 08:04:14 +0000	[thread overview]
Message-ID: <bug-107405-4-RGYI5X3JoP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107405-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107405

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jiri Slaby from comment #7)
> (In reply to Martin Liška from comment #2)
> > Note there's a similar issue I sent patch for:
> > https://lore.kernel.org/all/f70c7a11-e81e-f6b9-a403-315117f4aa3a@suse.cz/
> 
> ? I.e. how to %-format "B" in your example for both gcc-12 (c == 4) and
> gcc-13 (c == 8).

Just be consistent in the enumerator types within the same enum.
If you intend the whole enum to be int and its enumerators too,
use values that fit into int or cast the values explicitly to int.
So enum E { A = (int) 0xffffffff, B = -2 }; etc.
Or if you want the whole enum to have some other type (unsigned int, long,
unsigned long, long long, unsigned long long), use similar casts and/or
constant suffixes.
enum E { A = 0xffffffffU, B = -2U, C = (unsigned) 0xfffffffd } to get unsigned
int for everything, etc.

As written by Joseph in the commit log for PR36113 fix,
"This change was previously requested in PR 36113; it seems unlikely that
people are depending on the detail of the previous extension that some
enumerators had different types to others depending on whether their values
could be represented as int, and this patch makes the change to types of
enumerators unconditionally (if that causes problems in practice we could
always make it conditional on C2x mode instead)."
So, we have a proof that at least some projects (parts of Linux kernel) do rely
on this detail, now the big question is how often does this happen in the
kernel and if it affects anything else.  If it is widespread, as Joseph noted,
it could be restricted to C2X.  But you'll run into it when you switch to C2X
one day...

  parent reply	other threads:[~2022-10-26  8:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26  4:26 [Bug c/107405] New: enums can be long in gcc-13 jirislaby at gmail dot com
2022-10-26  4:28 ` [Bug c/107405] enums can be wrongly long in gcc-13 (in gnu99) jirislaby at gmail dot com
2022-10-26  6:55 ` marxin at gcc dot gnu.org
2022-10-26  7:08 ` marxin at gcc dot gnu.org
2022-10-26  7:27 ` jirislaby at gmail dot com
2022-10-26  7:31 ` jirislaby at gmail dot com
2022-10-26  7:45 ` jakub at gcc dot gnu.org
2022-10-26  7:53 ` jirislaby at gmail dot com
2022-10-26  8:04 ` jakub at gcc dot gnu.org [this message]
2022-10-26  8:21 ` redi at gcc dot gnu.org
2022-10-26  8:39 ` jirislaby at gmail dot com
2022-10-26  8:49 ` jirislaby at gmail dot com
2022-10-26 16:55 ` [Bug c/107405] [13 Regression] enum change causing Linux kernel to fail to build due to Linux depending on old behavior pinskia at gcc dot gnu.org
2022-10-26 17:35 ` joseph at codesourcery dot com
2022-10-28 11:19 ` rguenth at gcc dot gnu.org
2022-11-19  8:43 ` jakub at gcc dot gnu.org
2022-11-19 13:18 ` macro at orcam dot me.uk
2022-11-19 20:46 ` jakub at gcc dot gnu.org
2022-11-21 18:10 ` joseph at codesourcery dot com
2022-11-22 14:53 ` macro at orcam dot me.uk
2022-11-22 22:47 ` joseph at codesourcery dot com
2022-11-29 14:57 ` pinskia at gcc dot gnu.org
2023-01-13 11:36 ` rguenth at gcc dot gnu.org
2023-03-24  9:27 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107405-4-RGYI5X3JoP@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).