public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115109] New: Incorrect type of enumeration constant in redeclaration of enumeration constant (C23)
@ 2024-05-15 17:16 luigighiron at gmail dot com
  2024-05-16 20:58 ` [Bug c/115109] " jsm28 at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: luigighiron at gmail dot com @ 2024-05-15 17:16 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-19  8:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-15 17:16 [Bug c/115109] New: Incorrect type of enumeration constant in redeclaration of enumeration constant (C23) luigighiron at gmail dot com
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

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).