Subject: Re: [ub] What does "The function main shall not be used within a program" mean?
From: David Krauss (david_work_at_[hidden])
Date: 2014-01-22 02:29:44
On Jan 22, 2014, at 2:12 PM, Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
> On 22 January 2014 03:40, David Krauss <david_work_at_[hidden]> wrote:
>>>> 1. Violation of shall is diagnosable unless otherwise specified (1.4/1).
>>> Ok. I don't think this is obviously clear.
>> No? Its the usual blanket rule. Not clear if thats how compliance works, or if it applies in this instance?
Well, 1.4/1 covers it pretty succinctly. Every shall is a diagnosable rule unless explicitly modified by a weaker requirement. If memory serves, the library has a blanket rule that requirements of function parameters are not diagnosable. Also for what its worth, I remember that C excuses the implementation from diagnosing runtime conditions in general. But C++ takes the strategy of explicitly classifying each runtime rule as UB.
Theres nothing to weaken the diagnostic requirements on use of main. The implementations which don't are simply nonconforming.
>> Well, a definition is also a use, in the sense that the name is looked up. Also the linkage is implementation-defined, while if no aspect could ever be inspected, it might as well be merely implementation-specific.
>> I dont see what utility other uses could have though, given that ODR-use isnt allowed.
> I don't think decltype(main()) is an odr-use, or sizeof(decltype(main)).
True, I just dont see what utility those would be. You might mean sizeof(decltype(&main)) in the latter case.
I think the most common non-ODR use of main would be defining it after a forward declaration, and now Steven Clamage has clarified that should be ill-formed. The broader definition of use as being a result of name lookup without reference to ODR looks correct now.
each implementation is ultimately written for the satisfaction of its own customers, and there are enough folks who like to recurse main.
Its just surprising. Its legal in C and may be convenient for small programs, such as classroom examples.
>> I dont recall ever seeing an implementation not to allow safe recursion of main. Often the C runtime
> gcc doesn't allow it if given -pedantic.
I was only speaking of generated executable and runtime library layout.
SG12 list run by herb.sutter at gmail.com