Message ID | 573CF71D.3080503@oracle.com |
---|---|
State | New |
Headers | show |
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
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" } +}