]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Template keyword following :: [PR96082]
authorMarek Polacek <polacek@redhat.com>
Tue, 4 Aug 2020 13:35:25 +0000 (09:35 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 4 Aug 2020 18:16:36 +0000 (14:16 -0400)
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.

(cherry picked from commit 97def1f34c134d78d4423e9ac3e9b262417ea390)

gcc/cp/parser.c
gcc/testsuite/g++.dg/template/template-keyword3.C [new file with mode: 0644]

index ff0b2ed1ff0fb05db9e201eee0cfdfd661616b7f..5de13d0498fa5f34ed0dabc1f639bf154293eb9c 100644 (file)
@@ -18745,7 +18745,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
       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");
diff --git a/gcc/testsuite/g++.dg/template/template-keyword3.C b/gcc/testsuite/g++.dg/template/template-keyword3.C
new file mode 100644 (file)
index 0000000..91af2b3
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/96082
+// { dg-do compile { target c++11 } }
+
+template <class> class A {};
+
+void
+f ()
+{ 
+  typename::template A <int> a;
+  ::template A <int> a2;
+}