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



--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-16 
17:30:55 UTC ---

(In reply to comment #2)

> (In reply to comment #1)

> > As was explained on stackoverflow, this has nothing t odo with access

> > modifiers, as you can easily demonstrate by making everything public.

> > 

> > _t has not been declared at the point where you try to use it, so the name 
> > is

> > not in scope.  What are you claiming is a bug?

> 

> It might be my confusion but is that not altering modifiers ?



I don't know what you mean. Change "private" to "public", the code fails in

exactly the same way, therefore the problem is nothing to do with

accessibility.



> I am not sure why

> the initialisation list does not make the private member available (at least

> declared). 



The init list is a *use* of the member, not a declaration. Ctor init lists are

part of the function body, so only parsed once the class is complete.  You

could also use t_ in the constructor body, that doesn't mean it's in scope

outside that function body.





> On the clang mailing list this was hinted at as well, but I am not sure that

> this is a case where private: before public: does work and not vice versa

> although as I said it is very likely a c++ issue that I have just not come

> across yet (although I will remember as usual).



It has nothing to do with private vs public!



> Can you confirm why the _t is not available or declared when it is in the

> initialisation list ? does the decltype require earlier visibility than the 
> ctr

> ? 



See above. The init list is part of a function body. Function bodies are

processed when the class is complete, as though they were defined after the

class. Look:



struct A {

    A() : i(0) { ++i; }  // i is in scope



    decltype(i) get();  // error, i not in scope



    int i;   // i declared here



    decltype(i) get2();  // OK, i has been declared

};



This is equivalent to:



struct A {

    A();



    decltype(i) get();  // error, i not in scope



    int i;   // i declared here



    decltype(i) get2();  // OK, i has been declared

};



A::A() : i(0) { ++i; }  // OK, class is complete, i in scope.





In the first example the constructor can use 'i' in the init list and the ctor

body, that's OK. You can *not* use 'i' in a function signature before it's

declared. get() is an error, get2() is OK.

Reply via email to