Hi,

over the last weeks, while working on various batches of location improvements (a new one is forthcoming, in case you are wondering ;) I noticed this grokdeclarator diagnostic, one of those not exercised by our testsuite. While constructing a testcase I realized that probably it's better to immediately return error_mark_node, and avoid an additional redundant error about variable or field declared void or even about "fancy" variable templates, depending on the return type of the function template. Tested x86_64-linux.

Thanks, Paolo.

//////////////////////

/cp
2019-09-26  Paolo Carlini  <paolo.carl...@oracle.com>

        * decl.c (grokdeclarator): Immediately return error_mark_node
        upon error about template-id used as a declarator.

/testsuite
2019-09-26  Paolo Carlini  <paolo.carl...@oracle.com>

        * g++.dg/diagnostic/template-id-as-declarator-1.C: New.
Index: testsuite/g++.dg/diagnostic/template-id-as-declarator-1.C
===================================================================
--- testsuite/g++.dg/diagnostic/template-id-as-declarator-1.C   (nonexistent)
+++ testsuite/g++.dg/diagnostic/template-id-as-declarator-1.C   (working copy)
@@ -0,0 +1,5 @@
+template<typename>
+void foo() {}
+
+template void foo<int>(  // { dg-error "15:template-id .foo<int>. used as a 
declarator" }
+// { dg-error "expected" "" { target *-*-* } .-1 }
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 276151)
+++ cp/decl.c   (working copy)
@@ -12078,9 +12078,9 @@ grokdeclarator (const cp_declarator *declarator,
       && !FUNC_OR_METHOD_TYPE_P (type)
       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
     {
-      error ("template-id %qD used as a declarator",
-            unqualified_id);
-      unqualified_id = dname;
+      error_at (id_loc, "template-id %qD used as a declarator",
+               unqualified_id);
+      return error_mark_node;
     }
 
   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly

Reply via email to