public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc 3.4 - template problem
@ 2004-04-29  9:10 Lev Assinovsky
  2004-04-29 17:04 ` llewelly
  0 siblings, 1 reply; 2+ messages in thread
From: Lev Assinovsky @ 2004-04-29  9:10 UTC (permalink / raw)
  To: Gcc-Help (E-mail)

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?

Thanks in advance.
----
Lev Assinovsky
Aelita Software Corporation 
(now is a part of Quest Software)
O&S InTrust Framework Division, Team Leader
ICQ# 165072909

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gcc 3.4 - template problem
  2004-04-29  9:10 gcc 3.4 - template problem Lev Assinovsky
@ 2004-04-29 17:04 ` llewelly
  0 siblings, 0 replies; 2+ messages in thread
From: llewelly @ 2004-04-29 17:04 UTC (permalink / raw)
  To: Lev Assinovsky; +Cc: Gcc-Help (E-mail)

"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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-04-29 17:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-29  9:10 gcc 3.4 - template problem Lev Assinovsky
2004-04-29 17:04 ` llewelly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).