main
[[noexit]]
attribute, only
applicable to the function main
, as a hint to eliminate
destructor calls for objects with static storage duration. More
detailed rationale and discussion is available in the predecessor
paper N4226.
This paper was discussed during the November 2014 WG21 meeting in Urbana-Champaign. It was initially approved by the Evolution Working Group, but rejected by the Core Working Group. The latter opined that in order to benefit from the proposal, undesirable linker magic would be required. A way of specifying global options, attributes, or #pragmas visible in every translation unit would be preferred. After that, Evolution Working Group discussed this proposal again, noting that it supported the general idea, but required a more comprehensive paper analyzing the effects on different translation units, the effects on shared libraries, and the effects (such as undefined behavior) if violated. Also, measurements on the resource savings (such as ROM and RAM size) would be much appreciated.
This paper does not attempt to address the WG21 concerns raised in the discussion, it merely documents the state of the discussion to facilitate future work.
[ Note: The functionAdd a new section 7.6.6 dcl.attr.noexit:main
may be defined with thenoexit
attribute; see 7.6.6 dcl.attr.noexit. -- end note ]
7.6.6 [dcl.attr.noexit] Noexit attribute The attribute-tokenChange in 18.5 paragraph 6:noexit
specifies that a program never exits in a normal fashion. It shall appear at most once in each attribute-list and no attribute-argument-clause shall be present. The attribute may be applied to the declarator-id of the definition of the functionmain
(3.6.1 basic.start.main).If the function
main
is defined with thenoexit
attribute, leaving the functionmain
(3.6.1 basic.start.main) results in undefined behavior and an odr-use (3.2 basic.def.odr) of the functionstd::exit
in any translation unit is ill-formed; no diagnostic required. [ Note: The functionmain
may exit via an exception, in which casestd::terminate
is called (15.5.1 except.terminate). Destructors for objects with static storage duration are never invoked ifmain
is defined with thenoexit
attribute (3.6.3 basic.start.term). -- end note ]
Implementation limits: The implementation shall support the registration of at least 32 functions. [ Note: If the functionmain
is defined with thenoexit
attribute (7.6.6 dcl.attr.noexit), calling theatexit
function has no effect, since the functions so registered are never invoked. -- end note ]