The bug is: if a class definition has a nested template class, then whenever a code refers to a name in the nested class, gcc searches it not in the nested template class, but it the outer class.
The bug results in gcc accepting a source text that should not be compiled, and incorrectly compiling a valid source text. Complete compilable example is included at the end of this report. I was able to reproduce this behaviour back to gcc 4.2.1, 3.3.2 and 2.95.3. Explanation. Please consider the following class definition: struct root { template <typename Y> struct chain { }; }; As you see, the structure root::chain<any_type> has no members. However, gcc accepts and compiles type declarations like typedef root::chain<type_1>::chain<type_2>::chain<type_3> my_type; , where my_type becomes root::chain<type_3>, asif each "chain" template were looked up in the "root" class. You can use the following example to reproduce the bug. The example is compilable, which is wrong. //----------------------------------------------- struct root { template <typename Y> struct chain { }; }; struct o1; struct o2; struct o3; typedef root::chain<o1> p1; typedef root::chain<o2>::chain<o1> p2; /* <- should be error */ typedef root::chain<o3>::chain<o2>::chain<o1> p3; /* <- should be error */ int main() { p1 x1; p2 x2; p3 x3; x1 = x2 = x3; /* gcc thinks that they are of the same type! */ return 0; } -- Summary: Invalid member lookup when member template class is involved Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igusarov at mail dot ru GCC build triplet: amd64-unknown-freebsd7.1 GCC host triplet: amd64-unknown-freebsd7.1 GCC target triplet: amd64-unknown-freebsd7.1 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42692