public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "luigighiron at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-115109-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            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>=42);
enum E{a=1UL<<40,b=1};
enum E{a=1ULL<<40,b=_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:
> 
> - the previously declared type, if it is a redeclaration of the same
>   enumeration constant; or,
> 
> - the enumerated type, for an enumeration with fixed underlying type; or,
> 
> - int, if there are no previous enumeration constants in the enumerator list
>   and no explicit = with a defining integer constant expression; or,
> 
> - int, if given explicitly with = and the value of the integer constant
>   expression is representable by an int; or,
> 
> - the type of the integer constant expression, if given explicitly with = and
>   if the value of the integer constant expression is not representable by int;
>   or,
> 
>   ...
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 enumeration
constant 'a' unsigned long long because the type of the expression is unsigned
long long.

             reply	other threads:[~2024-05-15 17:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15 17:16 luigighiron at gmail dot com [this message]
2024-05-16 20:58 ` [Bug c/115109] " jsm28 at gcc dot gnu.org
2024-05-18 20:20 ` uecker at gcc dot gnu.org
2024-05-19  1:48 ` luigighiron at gmail dot com
2024-05-19  2:22 ` luigighiron at gmail dot com
2024-05-19  6:24 ` uecker at gcc dot gnu.org
2024-05-19  6:44 ` uecker at gcc dot gnu.org
2024-05-19 11:08 ` uecker at gcc dot gnu.org
2024-06-18 10:51 ` cvs-commit at gcc dot gnu.org
2024-06-19  7:56 ` clyon at gcc dot gnu.org
2024-06-19  8:09 ` uecker at gcc dot gnu.org
2024-06-19  8:17 ` jakub 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-115109-4@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).