In r9-4235 I tried to make sure that the template keyword follows
a nested-name-specifier.  :: is a valid nested-name-specifier, so
I also have to check 'globalscope' before giving the error.
gcc/cp/ChangeLog:
	PR c++/96082
	* parser.c (cp_parser_elaborated_type_specifier): Allow
	'template' following ::.
gcc/testsuite/ChangeLog:
	PR c++/96082
	* g++.dg/template/template-keyword3.C: New test.
       if (!template_p)
        cp_parser_parse_tentatively (parser);
       /* The `template' keyword must follow a nested-name-specifier.  */
-      else if (!nested_name_specifier)
+      else if (!nested_name_specifier && !globalscope)
        {
          cp_parser_error (parser, "%<template%> must follow a nested-"
                           "name-specifier");
 
--- /dev/null
+// PR c++/96082
+// { dg-do compile { target c++11 } }
+
+template <class> class A {};
+
+void
+f ()
+{ 
+  typename::template A <int> a;
+  ::template A <int> a2;
+}