C++ Logo

SG12

Advanced search

Subject: [ub] What does "The function main shall not be used within a program" mean?
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2014-01-21 18:49:13


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?


SG12 list run by herb.sutter at gmail.com