The following testcase fails to compile: template <typename data1> struct outer1 { typedef int my_value_type; // define a nested datatype template <typename servert> struct inner1 { typedef outer1<data1> myboss; // borrow the boss's datatype << -- don't reduce or change this one: typedef typename myboss::my_value_type my_value_type; my_value_type return_x(); }; }; // g++ 4 choked on this one: template <typename data1> template <typename servert> typename outer1<data1>::template inner1<servert>::my_value_type outer1<data1>::inner1<servert>::return_x() { return 4; } void testme() { outer1<float>::inner1<int> Inner1; int rslt = Inner1.return_x(); // to instantiate and cause error } It is basically like this: * outer1 class template has a nested datatype called "my_value_type" * inner1 borrows the "my_value_type" from outer1 (its parent) Then when we want to instantiate return_x() above, g++ gives the following error: template-typename4.cpp:19: error: prototype for ‘typename outer1<data1>::inner1<servert>::my_value_type outer1<data1>::inner1<servert>::return_x()’ does not match any in class ‘outer1<data1>::inner1<servert>’ template-typename4.cpp:10: error: candidate is: typename outer1<data1>::my_value_type outer1<data1>::inner1<servert>::return_x() template-typename4.cpp:19: error: template definition of non-template ‘typename outer1<data1>::inner1<servert>::my_value_type outer1<data1>::inner1<servert>::return_x()’ I can work around this by changing line 18 above: typename outer1<data1>::template inner1<servert>::my_value_type to typename outer1<data1>::my_value_type then it would compile. But I think this is a bug. It used to compile with g++ 3. Other compilers such as Intel C++ (version 9.1), PGI C++ 7 all accept this language construct.
The first snippet works for me, the second says t.C:3: error: expected nested-name-specifier before 'outer1' t.C:3: error: too many template-parameter-lists t.C: In function 'void testme()': t.C:11: error: 'outer1' was not declared in this scope t.C:11: error: expected primary-expression before 'float' t.C:11: error: expected `;' before 'float' t.C:12: error: 'Inner1' was not declared in this scope so - what is the testcase that you are looking at?
The whole snippet must be included the (un)desirable error to show up. Let me give an attachment to make it clear.
Created attachment 15047 [details] Sample code to cause compilation error.
*** Bug 35016 has been marked as a duplicate of this bug. ***
I believe we have a dup for this somewhere. Broken on the 4.1 and 4.2 branch.
Closing 4.2 branch, fixed in 4.3.