This is the mail archive of the gcc-bugs@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]

c++/9476: lookup of member in base class template fails


>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:


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