This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.4 - template problem
- From: llewelly at xmission dot com
- To: "Lev Assinovsky" <LAssinovsky at algorithm dot aelita dot com>
- Cc: "Gcc-Help (E-mail)" <gcc-help at gcc dot gnu dot org>
- Date: 29 Apr 2004 11:04:42 -0600
- Subject: Re: gcc 3.4 - template problem
- References: <3F6F4712B759A34ABD453A8B39C10D6202312846@bagman.edm.com>
"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.