diff options
author | Marek Polacek <polacek@redhat.com> | 2018-11-19 21:37:01 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2018-11-19 21:37:01 +0000 |
commit | 9047dd02b84c42d610cf84037cb7db8963245228 (patch) | |
tree | 06843088990a3eaf7367527146b567b20c44a2c9 /gcc | |
parent | 0da4824836328ffcc9a5d96a242756bad602d2fc (diff) | |
download | gcc-9047dd02b84c42d610cf84037cb7db8963245228.zip gcc-9047dd02b84c42d610cf84037cb7db8963245228.tar.gz gcc-9047dd02b84c42d610cf84037cb7db8963245228.tar.bz2 |
PR c++/87781 - detect invalid elaborated-type-specifier.
* 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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/elab3.C | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/crash115.C | 2 |
5 files changed, 27 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6f60f0d..f43d9c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 88fc426..292cce1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a659e7..4259616 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..61338fb --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/elab3.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/template/crash115.C b/gcc/testsuite/g++.dg/template/crash115.C index 5c9f525..80f8683 100644 --- a/gcc/testsuite/g++.dg/template/crash115.C +++ b/gcc/testsuite/g++.dg/template/crash115.C @@ -1,3 +1,3 @@ // PR c++/56534 -template < struct template rebind < > // { dg-error "expected" } +template < struct template rebind < > // { dg-error "expected|must follow" } |