[Bug c/113011] New: main declared with enumerated type is not accepted
luigighiron at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Dec 14 01:46:38 GMT 2023
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.
More information about the Gcc-bugs
mailing list