C++ Logo


Advanced search

Re: [ub] What does "The function main shall not be used within a program" mean?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 23 Jan 2014 00:51:27 +0200
On 22 January 2014 20:29, Richard Smith <richardsmith_at_[hidden]> wrote:
> 1.4/2, bullet 2, seems clear to me: this is a diagnosable rule, so a
> conforming implementation must issue at least one diagnostic for a program
> that violates it. (After doing so, if the implementation accepts it anyway,
> the behavior of the program is undefined, as for any diagnosable rule.)


>> I don't think decltype(main()) is an odr-use, or sizeof(decltype(main)).
> C++98's mention of 'use' had a cross-reference to 3.2 [basic.def.odr]. C++11
> no longer has the cross-reference, and was *not* changed to say 'odr-use',
> so I expect it means *any* use.


>> > I donít recall ever seeing an implementation not to allow safe recursion
>> > of main. Often the C runtime
>> gcc doesn't allow it if given -pedantic.
> Clang trunk also doesn't allow it with -pedantic-errors. Both GCC and Clang
> reject decltype(main()) too, in strictly-conforming mode. EDG rejects
> odr-uses of main but accepts uses that are not odr-uses.

It seems that gcc still allows this lovely piece of shenanigans:

int main() {int y = sizeof(decltype(main)*);}

Should this be a core issue? Apparently there has been, and still is,
implementation divergence.

Received on 2014-01-22 23:51:28