This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc 3.4 - template problem


"Lev Assinovsky" <LAssinovsky@algorithm.aelita.com> writes:

> Hi All!
> The program (tst.cpp) bellow can be compiled only after
> removing the comments /*A<T1>::*/:
> 
> template <class T> struct A
> {
>     T x;
> };
> 
> template <class T1> struct B: A<T1>
> {
>     B() { T1 y = /*A<T1>::*/x;}
> };
> 
> tst.cpp: In constructor `B<T1>::B()':
> tst.cpp:8: error: `x' undeclared (first use this function)
> 
> With gcc 3.2 everything is fine.
> Is it a bug of gcc 3.4 or my fault?

This happens because gcc 3.4 now implements two-phase name lookup, see
    http://gcc.gnu.org/gcc-3.4/changes.html and page down until you
    see the 2nd example in the C++ section, which is much like yours.

Also see DR 213
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#213

whose resolution adds:

        In the definition of a class template or a member of a class
        template, if a base class of the class template depends on a
        template-parameter, the base class scope is not examined
        during unqualified name lookup either at the point of
        definition of the class template or member or during an
        instantiation of the class template or member.

to the standard.

You can also use 'this->x' to make x dependent, making the
    implementation to look into the base class.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]