C++ Logo

sg12

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Wed, 22 Jan 2014 02:49:13 +0200
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?

Received on 2014-01-22 01:49:15