diff mbox

[C++,Patch/RFC] PR 70572 ("[4.9/5/6/7 Regression] ICE on code with decltype (auto) on x86_64-linux-gnu in digest_init_r")

Message ID 573CF71D.3080503@oracle.com
State New
Headers show

Commit Message

Paolo Carlini May 18, 2016, 11:13 p.m. UTC
Hi,

On 18/05/2016 23:13, Jason Merrill wrote:
> Shouldn't we have complained about declaring a variable with function 
> type before we get here?
Ah, interesting, I think all the other compilers I have at hand don't 
even try to catch the issue so early.

In any case, something as simple as the below appears to work, I'm 
finishing testing it. An earlier version didn't have the assignment of 
error_mark_node, which I added to avoid cases of redundant diagnostic 
later (eg, in check_field_decls for fields) and had a VAR_P (decl) check 
in the condition which doesn't seem necessary. What do you think?

Thanks,
Paolo.

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

Comments

Jason Merrill May 19, 2016, 1:58 p.m. UTC | #1
On 05/18/2016 07:13 PM, Paolo Carlini wrote:
> +	  error ("cannot declare variable %q+D with function type", decl);

I think the error message would be more helpful if it mentioned 
decltype(auto), maybe

"initializer for %<decltype(auto) %D%> has function type, did you forget 
the %<()%>?", DECL_NAME (decl)

(or some other way to print the variable type as declared rather than as 
deduced).

Jason
diff mbox

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 236433)
+++ cp/decl.c	(working copy)
@@ -6609,6 +6609,12 @@  cp_finish_decl (tree decl, tree init, bool init_co
                                                    adc_variable_type);
       if (type == error_mark_node)
 	return;
+      if (TREE_CODE (type) == FUNCTION_TYPE)
+	{
+	  error ("cannot declare variable %q+D with function type", decl);
+	  TREE_TYPE (decl) = error_mark_node;
+	  return;
+	}
       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     }
 
Index: testsuite/g++.dg/cpp1y/auto-fn31.C
===================================================================
--- testsuite/g++.dg/cpp1y/auto-fn31.C	(revision 0)
+++ testsuite/g++.dg/cpp1y/auto-fn31.C	(working copy)
@@ -0,0 +1,7 @@ 
+// PR c++/70572
+// { dg-do compile { target c++14 } }
+
+void foo ()
+{
+  decltype (auto) a = foo;  // { dg-error "cannot declare" }
+}