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

Ville Voutilainen ville.voutilainen at gmail.com
Wed Jan 22 01:49:13 CET 2014


An infinite recursion example:

int main() {auto* x = &main; x();}

A non-infinite one:

int x = 0; int main() {auto* f = &main; if (++x == 0) f();}

gcc rejects these with a diagnostic (when given -pedantic). clang does
not.

1) does a violation of a "shall" requirement mean UB in general,
or ill-formed (if ill-formed, is a diagnostic required?)?
2) what does it mean in this particular case?
3) why?


More information about the ub mailing list