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

* [Bug c/113011] main declared with enumerated type is not accepted
  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 ` pinskia at gcc dot gnu.org
  2023-12-14  2:02 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-14  1:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang even errors out:
<source>:6:1: error: 'main' must return 'int'
    6 | enum E main(){}
      | ^~~~~~
      | int

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

* [Bug c/113011] main declared with enumerated type is not accepted
  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
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-14  2:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From C99 draft: 5.1.2.2.1 Program startup
The function called at program startup is named main.The implementation
declares no prototype for this function. It shall be defined with a return type
ofintand with no parameters
...
or with two parameters (referred to here asargcandargv, though anynames may be
used, as theyare local to the function in which theyare declared):

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

* [Bug c/113011] main declared with enumerated type is not accepted
  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
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-14  2:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
C23 working draft has the same wording there too:
The function called at program startup is named main.The implementation
declares no prototype for this function. It shallbe defined with a return type
of int

Nowhere it says compatiable with int. just the return type of int.

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

* [Bug c/113011] main declared with enumerated type is not accepted
  2023-12-14  1:46 [Bug c/113011] New: main declared with enumerated type is not accepted luigighiron at gmail dot com
                   ` (2 preceding siblings ...)
  2023-12-14  2:04 ` pinskia at gcc dot gnu.org
@ 2023-12-14  2:04 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-14  2:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
C23 working draft can be found at
https://open-std.org/JTC1/SC22/WG14/www/docs/n3096.pdf .

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