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.
/////////////////////
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" }
+}