public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113011] New: main declared with enumerated type is not accepted
@ 2023-12-14  1:46 luigighiron at gmail dot com
  2023-12-14  1:54 ` [Bug c/113011] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: luigighiron at gmail dot com @ 2023-12-14  1:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113011
           Summary: main declared with enumerated type is not accepted
           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: ---

The following code is rejected in GCC with pedantic mode enabled:

enum E{e=-1};
_Static_assert(
    _Generic((enum E)e,int:1,default:0),
    "incorrect enumeration type"
);
enum E main(){}

If the static assertion succeeds, then the type enum E is compatible with int.
Given that enum E is compatible with int, it should be a valid return type of
main:

> If the return type of the main function is a type compatible with int,
> a return from the initial call to the main function is equivalent to
> calling the exit function with the value returned by the main function
> as its argument; reaching the } that terminates the main function returns
> a value of 0. If the return type is not compatible with int, the termination
> status returned to the host environment is unspecified.
Section 5.1.2.2.3 "Program termination" Paragraph 1 ISO/IEC 9899:2018

Additionally, here is the paragraph explaining that an enumerated type is
compatible with its underlying type:

> Each enumerated type shall be compatible with char, a signed integer type,
> or an unsigned integer type. The choice of type is implementation-defined,
> but shall be capable of representing the values of all the members of the
> enumeration.
Section 6.7.2.2 "Enumeration specifiers" Paragraph 4 ISO/IEC 9899:2018

Outside of pedantic mode, GCC accepts the code but returns a non-zero value
when the closing brace is reached which isn't correct either.

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

end of thread, other threads:[~2023-12-14  2:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-14  1:46 [Bug c/113011] New: main declared with enumerated type is not accepted luigighiron at gmail dot com
2023-12-14  1:54 ` [Bug c/113011] " pinskia at gcc dot gnu.org
2023-12-14  2:02 ` pinskia at gcc dot gnu.org
2023-12-14  2:04 ` pinskia at gcc dot gnu.org
2023-12-14  2:04 ` pinskia 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).