[C++ Patch] PR 84423 ("[6/7/8/9 Regression] [concepts] ICE with invalid using declaration")

Paolo Carlini paolo.carlini@oracle.com
Fri Sep 28 20:26:00 GMT 2018


Hi,

On 9/28/18 7:18 PM, Jason Merrill wrote:
> On Fri, Sep 28, 2018 at 12:42 PM, Paolo Carlini
> <paolo.carlini@oracle.com> wrote:
>> Hi,
>>
>> the primary issue here is a rather straightforward error-recovery, where,
>> after a sensible (but see below) error message we ICE in
>> get_underlying_template - called by convert_template_argument - because we
>> don't handle correctly error_mark_node as TREE_TYPE, as set in
>> grokdeclarator. While working on it I noticed that the error message emitted
>> by grokdeclarator seems suboptimal, because, per 10.1.3/2, we correctly
>> handle the alias declaration like a typedef but, I believe, we don't want to
>> just say *typedef* in the error message: luckily the infrastructure to be
>> more accurate is fully available, because we need it to set
>> TYPE_DECL_ALIAS_P anyway.
> OK, though as long as you're messing with this error you might want to
> improve its location as well.

Thanks. About the location, you are certainly right, but doesn't seem 
trivial. Something we can do *now* is using 
declspecs->locations[ds_typedef] and declspecs->locations[ds_alias], but 
that gives us the location of the keyword 'typedef' and 'using', 
respectively, whereas I think that we would like to have the location of 
'auto' itself. I could look into that as a follow-up piece work (by the 
way, I'm always reluctant to embark in non trivial work having to do 
with locations because I suppose David is already on it?!?)

Paolo.

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

-------------- next part --------------
Index: constraint.cc
===================================================================
--- constraint.cc	(revision 264687)
+++ constraint.cc	(working copy)
@@ -1164,6 +1164,9 @@ build_constraints (tree tmpl_reqs, tree decl_reqs)
   if (!tmpl_reqs && !decl_reqs)
     return NULL_TREE;
 
+  //if (tmpl_reqs == error_mark_node || decl_reqs == error_mark_node)
+  //return NULL_TREE;
+
   tree_constraint_info* ci = build_constraint_info ();
   ci->template_reqs = tmpl_reqs;
   ci->declarator_reqs = decl_reqs;
Index: decl.c
===================================================================
--- decl.c	(revision 264687)
+++ decl.c	(working copy)
@@ -11879,6 +11879,7 @@ grokdeclarator (const cp_declarator *declarator,
   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   if (typedef_p && decl_context != TYPENAME)
     {
+      bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
       tree decl;
 
       /* This declaration:
@@ -11901,7 +11902,12 @@ grokdeclarator (const cp_declarator *declarator,
 
       if (type_uses_auto (type))
 	{
-	  error ("typedef declared %<auto%>");
+	  if (alias_p)
+	    error_at (declspecs->locations[ds_alias],
+		      "%<auto%> not allowed in alias declaration");
+	  else
+	    error_at (declspecs->locations[ds_typedef],
+		      "typedef declared %<auto%>");
 	  type = error_mark_node;
 	}
 
@@ -11961,7 +11967,7 @@ grokdeclarator (const cp_declarator *declarator,
 		      inlinep, friendp, raises != NULL_TREE,
 		      declspecs->locations);
 
-      if (decl_spec_seq_has_spec_p (declspecs, ds_alias))
+      if (alias_p)
 	/* Acknowledge that this was written:
 	     `using analias = atype;'.  */
 	TYPE_DECL_ALIAS_P (decl) = 1;
Index: pt.c
===================================================================
--- pt.c	(revision 264687)
+++ pt.c	(working copy)
@@ -7776,7 +7776,7 @@ convert_template_argument (tree parm,
   tree val;
   int is_type, requires_type, is_tmpl_type, requires_tmpl_type;
 
-  if (parm == error_mark_node)
+  if (parm == error_mark_node || error_operand_p (arg))
     return error_mark_node;
 
   /* Trivially convert placeholders. */


More information about the Gcc-patches mailing list