Bug 19189 - A derived template cannot access base template members without using this
Summary: A derived template cannot access base template members without using this
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-29 14:30 UTC by Amos Ortal
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: MinGW on WinXP
Target: MinGW on WinXP
Build: gcc version 3.4.2 (mingw-special)
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Amos Ortal 2004-12-29 14:30:46 UTC
If you try to access a member of a base template from a derived template (event
if the member is public) you are getting a compilation error.
This is a regression related to previous versions of the compiler (worked in
3.3.3) and I think its not ANSI C++ as well.

For example, compiling the following code (in test.cpp) will issue these errors:
$ g++ -c test.cpp 
test.cpp: In member function `virtual bool Derived<Concept>::test(Concept)':
test.cpp:21: error: `xxx' undeclared (first use this function)
test.cpp:21: error: (Each undeclared identifier is reported only once for each f
                                               unction it appears in.)

------------
test.cpp
------------
// The base template
template <class Concept> class Base 
{
public :
    int xxx;     
};

// The derived template
template <class Concept> class Derived : public Base<Concept> 
{
public :
	bool test(Concept p)
	{
        return (xxx > 10); // to fix this I need to modify it to: return
(this->xxx > 10);
    }
};

// usage
bool call_test(Derived<int>& d)
{
	return d.test(5);
}
Comment 1 Andrew Pinski 2004-12-29 14:33:35 UTC
Does anyone read the release notes?

Yes this is required by the C++ standard.
Comment 2 Andrew Pinski 2004-12-29 14:58:05 UTC
Subject: Re:  A derived template cannot access base templat e members without using this


On Dec 29, 2004, at 9:54 AM, Amos Ortal wrote:

> Hi Andrew,
>
> Thank you for your fast reply, I saw the entry in the release notes 
> but it doesn't point to the standard and I could not find it.
>
> Can you please point me to the section in the standard that specify 
> this?

14.6, the whole section is about name resolution in templates.

-- Pinski

Comment 3 Giovanni Bajo 2004-12-29 16:59:55 UTC
Specifically, [temp.dep]/3. Besides, even if the release notes do not point you 
to a specific place in the standard, the fact that we even documented that it's 
a *wanted* change in behaviour, it means it has to be correct, don't you think?
Comment 4 Giovanni Bajo 2004-12-29 17:04:17 UTC
BTW, I just added the standard reference to the release notes as well.
Comment 5 Amos Ortal 2004-12-30 07:32:59 UTC
(In reply to comment #3):
I agree that this is the expected behavior, although such a change, without any
backward compatibility, makes it hard to upgrade to a new version of the compiler.
In our specific case, we provide a generic library and a client that tried to
upgrade found the error and didn't understand why (they didn't read the release
notes as well). Also the error message doesn't help you to understand that this
is a deliberate change.