main with attributesAuthors: Jay Ghiron
Date: 2026-05-15
Submitted against: C23
Status: Open
Cross-references: 1013
main cannot be declared with the _Noreturn function specifier:
In a hosted environment, no function specifier(s) shall appear in a declaration of
main.
(C23 6.7.5 "Function specifiers" paragraph 4.)
However, there does not appear to be any equivalent wording for the
[[noreturn]] attribute directly preventing its use with main:
[[noreturn]]int main(){
for(;;);
}
It is worth noting that other translation units must equivalently use
[[noreturn]], that is the following translation unit would cause
undefined behavior in combination with the previous translation unit:
int main();
Additionally, it is unclear whether or not [[reproducible]] and
[[unsequenced]] can be used on the type of main. See also issue
1013 which discusses type equivalence with these
attributes. For the following questions, assume that the
implementation is hosted and supports no additional types of main.
Is the following definition of main valid?
[[noreturn]]int main(){
for(;;);
}
Is the following definition of main valid?
int main()[[reproducible]]{}
Is the following definition of main valid?
int main()[[unsequenced]]{}
Comment from Issues list maintainer on 2026-11-27:
This issue was discussed at the November 2026 (Búzios) meeting of
WG14. It was noted that the C23 wording (5.2.2.3.2 Program startup)
saying "or equivalent" for declarations of main was changed for C2Y
in N3623
to say "or using another type that is compatible with one of these two
function types", and there was support for saying that all three
examples are intended to be valid in C23, based on the clarified
wording in C2Y; it was also suggested that implementation-defined
attributes, in particular, should be allowed on main. There was a
suggestion of changing _Noreturn to match the rules for
[[noreturn]] here, but also a suggestion that this is not needed for
an obsolescent feature. Joseph Myers took an action item to write a
response on the basis that all three examples are intended to be
valid.