From: Marek Polacek Date: Thu, 26 Mar 2020 20:07:17 +0000 (-0400) Subject: c++: template keyword accepted before destructor names [PR94336] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=71d69548a1b2c85220ac6354564fd272beb9263f;p=gcc.git c++: template keyword accepted before destructor names [PR94336] This came up on the C++ core list recently. We don't diagnose the case when 'template' is followed by a destructor name which is not permitted by [temp.names]/5. PR c++/94336 - template keyword accepted before destructor names. * parser.c (cp_parser_unqualified_id): Give an error when 'template' is followed by a destructor name. * g++.dg/template/template-keyword2.C: New test. --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index da556a4914e..6ac6a67933a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-03-26 Marek Polacek + + PR c++/94336 - template keyword accepted before destructor names. + * parser.c (cp_parser_unqualified_id): Give an error when 'template' + is followed by a destructor name. + 2020-03-27 Patrick Palka * decl.c (compute_array_index_type_loc): Remove redundant diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 753b3148ab3..1afd03d3863 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6068,6 +6068,15 @@ cp_parser_unqualified_id (cp_parser* parser, cp_lexer_consume_token (parser->lexer); return error_mark_node; } + if (template_keyword_p) + { + if (!cp_parser_uncommitted_to_tentative_parse_p (parser)) + error_at (tilde_loc, "% keyword not permitted in " + "destructor name"); + cp_parser_simulate_error (parser); + return error_mark_node; + } + gcc_assert (!scope || TYPE_P (scope)); token = cp_lexer_peek_token (parser->lexer); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4cbfdcafa99..3a1c5e713dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-26 Marek Polacek + + PR c++/94336 - template keyword accepted before destructor names. + * g++.dg/template/template-keyword2.C: New test. + 2020-03-27 Iain Sandoe * g++.dg/coroutines/torture/symmetric-transfer-00-basic.C: diff --git a/gcc/testsuite/g++.dg/template/template-keyword2.C b/gcc/testsuite/g++.dg/template/template-keyword2.C new file mode 100644 index 00000000000..27d874ba7d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/template-keyword2.C @@ -0,0 +1,5 @@ +// PR c++/94336 - template keyword accepted before destructor names. + +template void f(T *p) { p->template ~X(); } // { dg-error ".template. keyword not permitted in destructor name" } +template struct X {}; +void g(X *p) { f(p); }