This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9476: lookup of member in base class template fails
- From: jan at etpmod dot phys dot tue dot nl
- To: gcc-gnats at gcc dot gnu dot org
- Date: 28 Jan 2003 12:57:33 -0000
- Subject: c++/9476: lookup of member in base class template fails
- Reply-to: jan at etpmod dot phys dot tue dot nl
>Number: 9476
>Category: c++
>Synopsis: lookup of member in base class template fails
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Jan 28 13:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Jan van Dijk
>Release: gcc version 3.4 20030128 (experimental)
>Organization:
>Environment:
Linux 2.5.59, glibc-2.2.5
>Description:
gcc-head fails to compile he accompanying code:
gcctest.cpp: In member function `void D<T>::bad()':
gcctest.cpp:12: error: `i' has not been declared
Qualifying i as B<T>::i (thus making i a dependent name explicitly) fixes the problem, see ugly(). To my surprise, look up of member variables is now different from that of member functions: f() does not need to be qualified (see good()).
Comments from Nathan Sidwell on the mailing list:
refer to 14.6/8 in your example both i and f are non-dependent names so the usual lookup rules apply. 3.4.1, 3.4.2. 3.4.1 deals with non-function call unqualified name lookup (i), and 3.4.2 deals with
unqualified names used for function calls. That uncludes koenig lookup. In this case there are no template-dependent arguments, so the koenig lookup should be resolved at parse time. (see example in 14.6/9)
<snip>
void good(){ f(); } // no B<T>:: required
If you said &f;, you'd get the same error. I think this is a bug,
please file a bug report.
>How-To-Repeat:
template <class T>
struct B
{
int i;
int f();
};
template <class T>
struct D : public B<T>
{
void good(){ f(); } // no B<T>:: required
void bad(){ i=0 // does not compile
void ugly(){ B<T>::i=0; } // ... this does.
};
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: