From 9047dd02b84c42d610cf84037cb7db8963245228 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 19 Nov 2018 21:37:01 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 8 ++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/parse/elab3.C | 6 ++++++ gcc/testsuite/g++.dg/template/crash115.C | 2 +- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/elab3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6f60f0d57f9..f43d9c4fea9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-11-19 Marek Polacek + + 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 * decl2.c (grokfield): Remove obsolete _vptr check; fix diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 88fc426102b..292cce15676 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, "% 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 6a659e73680..42596160f96 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-11-19 Marek Polacek + + 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 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 00000000000..61338fb7ac4 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/elab3.C @@ -0,0 +1,6 @@ +// PR c++/87781 +// { dg-do compile } +// { dg-options "" } + +template class A; +class template A *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 5c9f525cd64..80f8683a136 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" } -- 2.30.2