This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: G++ refuses to compile simple, looking good code
- From: Florian Weimer <fweimer at redhat dot com>
- To: Luchezar Belev <lukcho at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 14 Jun 2013 11:34:41 +0200
- Subject: Re: G++ refuses to compile simple, looking good code
- References: <CAJtzQrxJWGjSnrOLqTBoPCgPsdECX2n=nZbJPRCP_Jik=_P1Zw at mail dot gmail dot com>
On 06/14/2013 11:30 AM, Luchezar Belev wrote:
Hi,
i'm not a c++/template guru and i can't decide if this is really a
valid code or i have encountered a gcc bug:
------------------------------
template <class T> struct A {
void *p;
};
template <class T> struct B : A<T> {
void *foo() { return p; }
};
------------------------------
g++ says "error: 'p' was not declared in this scope".
microsoft's compiler is happy with the same code.
Current MSVC in standard C++ mode? That's odd.
The compiler doesn't now the members of A<T> when the B template is
compiled. (There might be a partial specialization later in the file.)
Therefore, you must explicitly request dependent name lookup by
dereferencing the this pointer:
template <class T> struct B : A<T> {
void *foo() { return this->p; }
};
--
Florian Weimer / Red Hat Product Security Team