The following code fails to compile this.cpp: In member function 'int foo<T>::baz::foo()': this.cpp:8: error: 'i' was not declared in this scope
// begin this.cpp template <class T> struct foo { struct bar { int i; }; struct baz : bar { int foo() { return i; } }; }; int main() { } // end this.cpp Changing it to 'this->val' solves the problem, but is unwieldy for classes with lots of members. I'm unsure what the Standard says, but I thought you only needed 'this->' when the member depends on information the compiler won't have until template instantiation time. However, that doesn't really apply here -- foo and bar do not depend on the template's type, so the compiler should be able to figure things out well before the template gets instantiated. FWIW Sun's CC accepts the code with no warnings. It's usually much more strict than gcc (to the point of being really frustrating). Even if the Standard says gcc is right, it would be very convenient if gcc matched CC on this "extension". -- Summary: Scope broken for inherited members inside template class? Product: gcc Version: 4.2.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: scovich at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34184