http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 
13:38:11 UTC ---
(In reply to comment #10)
> (In reply to comment #9)
> 
> > No, the variable is in scope after its identifier, so it can be used in the
> > initializer expression, e.g.
> > 
> > int i = sizeof(i);  // ok
> > int i = i+1;  // not ok
> 
> My opinion is that C habit rules here.
> 
> In C
> 
> int i=i+1; -> int i; i=i+1;

In C++ this can be written:

int i(i+1);

The initialization rules for C++ do 

> without constructors, objects e.t.c.
> This example will bring just a warning.
> 
> In C++
> 
> Class i(i.Method()); eval i.Method() -> construct with Class::Class(result)

Note that this is similar to:

Class i = i.Method();

For the purposes of your complaint it's not relevant that it's a class with a
constructor.

Obviously "i.Method()" has to be evaluated first at runtime, but that doesn't
make it a compile-time error.  "i" is in scope as soon a "Class i" has been
parsed, so the expression "i.Method()" in the initializer can be compiled.

> another order of calculation. (see comment 2) Must be an error.

No.  The behaviour at runtime is undefined, but it is not an error at compile
time - the syntax is valid, but the result is undefined.

I understand what you're saying, but you're wrong. C++ doesn't work how you
think it works.

Reply via email to