]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add fixup to missing .template warning
authorJason Merrill <jason@redhat.com>
Wed, 29 Jun 2022 21:12:09 +0000 (17:12 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 1 Jul 2022 14:49:23 +0000 (10:49 -0400)
I experimented with giving this diagnostic in another place, which didn't
work out, but we can still benefit from adding the fixup.

gcc/cp/ChangeLog:

* parser.cc (missing_template_diag): Split out...
(cp_parser_id_expression): ...from here.

gcc/cp/parser.cc

index 357fde557c7516ea36799d5c4ce9f7278196cd1e..f6bc8db8581472a296a0ee0384209dfa732494df 100644 (file)
@@ -6093,6 +6093,23 @@ cp_parser_primary_expression (cp_parser *parser,
                                       /*decltype*/false, idk);
 }
 
+/* Complain about missing template keyword when naming a dependent
+   member template.  */
+
+static void
+missing_template_diag (location_t loc, diagnostic_t diag_kind = DK_WARNING)
+{
+  if (warning_suppressed_at (loc, OPT_Wmissing_template_keyword))
+    return;
+
+  gcc_rich_location richloc (loc);
+  richloc.add_fixit_insert_before ("template");
+  emit_diagnostic (diag_kind, &richloc, OPT_Wmissing_template_keyword,
+                  "expected %qs keyword before dependent "
+                  "template name", "template");
+  suppress_warning_at (loc, OPT_Wmissing_template_keyword);
+}
+
 /* Parse an id-expression.
 
    id-expression:
@@ -6268,9 +6285,7 @@ cp_parser_id_expression (cp_parser *parser,
             operator.  */
          && (cp_lexer_peek_token (parser->lexer)->type
              <= CPP_LAST_PUNCTUATOR))
-       warning_at (token->location, OPT_Wmissing_template_keyword,
-                   "expected %qs keyword before dependent "
-                   "template name", "template");
+       missing_template_diag (token->location);
     }
 
   return id;