@@ -32337,8 +32337,6 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags,
&& next_token->type != CPP_TEMPLATE_ID)
return false;
- const bool saw_template_id = (next_token->type == CPP_TEMPLATE_ID);
-
/* Parse tentatively; we are going to roll back all of the tokens
consumed here. */
cp_parser_parse_tentatively (parser);
@@ -32558,7 +32556,7 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags,
/* DR 2237 (C++20 only): A simple-template-id is no longer valid as the
declarator-id of a constructor or destructor. */
if (constructor_p
- && saw_template_id
+ && cp_lexer_peek_token (parser->lexer)->type == CPP_TEMPLATE_ID
&& !cp_parser_uncommitted_to_tentative_parse_p (parser))
{
auto_diagnostic_group d;
new file mode 100644
@@ -0,0 +1,7 @@
+// PR c++/97202
+// { dg-options "" }
+
+template<typename Base> struct S : Base {
+ inline S<Base>() {} // { dg-warning "template-id not allowed for constructor" "" { target c++20 } }
+ inline ~S<Base>() {} // { dg-warning "template-id not allowed for destructor" "" { target c++20 } }
+};