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.
This commit is contained in:
Marek Polacek 2020-03-26 16:07:17 -04:00
parent 54f58e9416
commit 71d69548a1
4 changed files with 25 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2020-03-26 Marek Polacek <polacek@redhat.com>
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 <ppalka@redhat.com>
* decl.c (compute_array_index_type_loc): Remove redundant

View File

@ -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, "%<template%> 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);

View File

@ -1,3 +1,8 @@
2020-03-26 Marek Polacek <polacek@redhat.com>
PR c++/94336 - template keyword accepted before destructor names.
* g++.dg/template/template-keyword2.C: New test.
2020-03-27 Iain Sandoe <iain@sandoe.co.uk>
* g++.dg/coroutines/torture/symmetric-transfer-00-basic.C:

View File

@ -0,0 +1,5 @@
// PR c++/94336 - template keyword accepted before destructor names.
template<typename T> void f(T *p) { p->template ~X(); } // { dg-error ".template. keyword not permitted in destructor name" }
template<typename T> struct X {};
void g(X<int> *p) { f(p); }