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

David Krauss david_work at me.com
Wed Jan 22 01:55:21 CET 2014


1. Violation of “shall” is diagnosable unless otherwise specified (1.4/1).
2. I would take “use” to mean ODR-use.
3. Far as I know, the implementation is allowed to perform dynamic initialization of globals in main. So for all intents and purposes, it’s not really usable as a function because its body doesn’t describe what it does.

On Jan 22, 2014, at 8:49 AM, Ville Voutilainen <ville.voutilainen at gmail.com> wrote:

> 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?
> _______________________________________________
> ub mailing list
> ub at isocpp.open-std.org
> http://www.open-std.org/mailman/listinfo/ub



More information about the ub mailing list