The change for 54769 caused us to accept this invalid ::template A even though the scope is non-dependent, so we can do the lookup. Fixed by reverting part of the change to cp_parser_template_name, which isn't actually needed.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit a553e80cfd772d103963b5176af17f9e8232c1c7 Author: Jason Merrill <ja...@redhat.com> Date: Fri Jun 30 16:38:14 2017 -0400 PR c++/81257 - ICE with invalid ::template. PR c++/54769 - wrong lookup of dependent template-name. * parser.c (cp_parser_template_name): Revert part of last change. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c6a8e37..575dbfc 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15911,11 +15911,6 @@ cp_parser_template_name (cp_parser* parser, /*ambiguous_decls=*/NULL, token->location); - /* If the lookup failed and we got the 'template' keyword, believe it. */ - if (decl == error_mark_node && template_keyword_p - && processing_template_decl) - return identifier; - decl = strip_using_decl (decl); /* If DECL is a template, then the name was a template-name. */ diff --git a/gcc/testsuite/g++.dg/parse/template-keyword1.C b/gcc/testsuite/g++.dg/parse/template-keyword1.C new file mode 100644 index 0000000..0a1298e --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/template-keyword1.C @@ -0,0 +1,3 @@ +// PR c++/81257 + +template < typename ::template A < int > >; // { dg-error "" }