[ub] What does "The function main shall not be used within a program" mean?
David Krauss
david_work at me.com
Thu Jan 23 03:00:15 CET 2014
On Jan 23, 2014, at 2:29 AM, Richard Smith <richardsmith at google.com> wrote:
> 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 looks like Clang and GCC reject unevaluated call expressions and unary & expressions, but other non-ODR uses go undetected.
(void) main; // no diagnosis
(void) & main; // diagnosis
Also, this ODR use which avoids function pointer conversion gets no diagnosis from either.
template< int (&)() >
struct s {};
s< main > q; // no diagnosis
GCC diagnoses this analogous case, but Clang does not; it happily generates the recursive program.
#include <iostream>
void f( int (&p)() ) { p(); }
int main() {
std::cout << "hello\n";
f( main ); // GCC diagnosis, not Clang.
}
For the record, the GCC manual says that -pedantic and -pedantic-errors are required to get ISO-required diagnoses that aren’t “gratuitous.” So it seems there’s no sense worrying what they allow in non-pedantic mode.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/ub/attachments/20140123/1c7336a9/attachment.html
More information about the ub
mailing list