C++ Logo

sg12

Advanced search

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

From: David Krauss <david_work_at_[hidden]>
Date: Wed, 22 Jan 2014 08:55:21 +0800
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_[hidden]> 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_[hidden]
> http://www.open-std.org/mailman/listinfo/ub

Received on 2014-01-22 01:55:39