PR c++/87781 - detect invalid elaborated-type-specifier.
authorMarek Polacek <polacek@redhat.com>
Mon, 19 Nov 2018 21:37:01 +0000 (21:37 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 19 Nov 2018 21:37:01 +0000 (21:37 +0000)
* parser.c (cp_parser_elaborated_type_specifier): Ensure that
typename follows a nested-name-specifier.

* g++.dg/parse/elab3.C: New test.
* g++.dg/template/crash115.C: Adjust dg-error.

From-SVN: r266285

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/elab3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash115.C

index 6f60f0d57f943e8b1156fb79e017a4f7c4d5a38a..f43d9c4fea9b8ebff85cab1a4da1639bec0bf6bb 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-19  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87781 - detect invalid elaborated-type-specifier.
+       * parser.c (cp_parser_elaborated_type_specifier): Ensure that
+       typename follows a nested-name-specifier.
+
 2018-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * decl2.c (grokfield): Remove obsolete _vptr check; fix
index 88fc426102b04168273b69ac14e5fc5576821caa..292cce156769282f761ac2807e02ff59f300ae8c 100644 (file)
@@ -18009,6 +18009,14 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
         template-id or not.  */
       if (!template_p)
        cp_parser_parse_tentatively (parser);
+      /* The `template' keyword must follow a nested-name-specifier.  */
+      else if (!nested_name_specifier)
+       {
+         cp_parser_error (parser, "%<template%> must follow a nested-"
+                          "name-specifier");
+         return error_mark_node;
+       }
+
       /* Parse the template-id.  */
       token = cp_lexer_peek_token (parser->lexer);
       decl = cp_parser_template_id (parser, template_p,
index 6a659e736802c010b30187d7ed994d7176b05845..42596160f96e97f659f874d2eb8ecf3d3ec4ab38 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-19  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87781 - detect invalid elaborated-type-specifier.
+       * g++.dg/parse/elab3.C: New test.
+       * g++.dg/template/crash115.C: Adjust dg-error.
+
 2018-11-19  Peter Bergner  <bergner@linux.ibm.com>
 
        PR rtl-optimization/88033
diff --git a/gcc/testsuite/g++.dg/parse/elab3.C b/gcc/testsuite/g++.dg/parse/elab3.C
new file mode 100644 (file)
index 0000000..61338fb
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/87781
+// { dg-do compile }
+// { dg-options "" }
+
+template<class> class A;
+class template A<int> *p; // { dg-error ".template. must follow|invalid" }
index 5c9f525cd64704e751ceddb0ba952b1d4dbcb4ba..80f8683a1366e591d3870f15ecc9b7693f9b050f 100644 (file)
@@ -1,3 +1,3 @@
 // PR c++/56534
 
-template < struct template rebind < > // { dg-error "expected" }
+template < struct template rebind < > // { dg-error "expected|must follow" }