Index: testsuite/g++.dg/template/typename15.C =================================================================== --- testsuite/g++.dg/template/typename15.C (revision 0) +++ testsuite/g++.dg/template/typename15.C (revision 0) @@ -0,0 +1,10 @@ +// { dg-do compile } + +// This should fail as A::foo<0> is not a typename at all. +struct A +{ + template void foo(int i) + { + typename A::foo<0>(i1); // { dg-error "" } + } +}; Index: testsuite/g++.dg/template/typename16.C =================================================================== --- testsuite/g++.dg/template/typename16.C (revision 0) +++ testsuite/g++.dg/template/typename16.C (revision 0) @@ -0,0 +1,14 @@ +// { dg-do compile } + +// These typename should work as they are types. +struct A +{ + typedef int a; + template + struct f {}; + template void foo(int i) + { + typename A::a(i1); + typename A::f<0>(i2); + } +}; Index: cp/parser.c =================================================================== --- cp/parser.c (revision 142989) +++ cp/parser.c (working copy) @@ -11537,7 +11537,11 @@ cp_parser_elaborated_type_specifier (cp_ type = make_typename_type (parser->scope, decl, typename_type, /*complain=*/tf_error); - else + /* If the `typename' keyword is in effect and DECL is not a type decl. Then + type is non existant. */ + else if (tag_type == typename_type && TREE_CODE (decl) != TYPE_DECL) + type = NULL_TREE; + else type = TREE_TYPE (decl); }