Message ID | 4DDE9C50.7050601@oracle.com |
---|---|
State | New |
Headers | show |
On 05/26/2011 08:30 PM, Paolo Carlini wrote: > ...also, not returning error_mark_node unconditionally, means a better > diagnostic, without redundant "array bound is not an integer constant > before...". Just noticed that outside a template, we do indeed emit the additional "array bound is not an integer constant before..." message. If we want it, I have just to return error_mark_node unconditionally. Just let me know. Paolo.
On 05/26/2011 02:30 PM, Paolo Carlini wrote: > We want to do that only when processing a template, because otherwise we > get a duplicate diagnostic, see, eg, auto9.C Hmm, where's the error coming from in the non-template case? From cp_build_c_cast? In that case always giving the error in build_functional_cast and then returning error_mark_node should avoid duplication. > error_mark_node unconditionally, means a better diagnostic, without > redundant "array bound is not an integer constant before...". I'd rather deal with that by suppressing that error if we already have error_mark_node. Jason
Index: testsuite/g++.dg/cpp0x/auto25.C =================================================================== --- testsuite/g++.dg/cpp0x/auto25.C (revision 0) +++ testsuite/g++.dg/cpp0x/auto25.C (revision 0) @@ -0,0 +1,7 @@ +// PR c++/42056 +// { dg-options -std=c++0x } + +template<int> struct A +{ + int a[auto(1)]; // { dg-error "invalid use of" } +}; Index: testsuite/g++.dg/cpp0x/auto26.C =================================================================== --- testsuite/g++.dg/cpp0x/auto26.C (revision 0) +++ testsuite/g++.dg/cpp0x/auto26.C (revision 0) @@ -0,0 +1,7 @@ +// PR c++/42056 +// { dg-options -std=c++0x } + +template<int> void foo() +{ + int a[auto(1)]; // { dg-error "invalid use of" } +} Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 174301) +++ cp/typeck2.c (working copy) @@ -1603,6 +1603,14 @@ build_functional_cast (tree exp, tree parms, tsubs { tree t; + if (type_uses_auto (type)) + { + if (complain & tf_error) + error ("invalid use of %<auto%>"); + else + return error_mark_node; + } + /* Diagnose this even in a template. We could also try harder to give all the usual errors when the type and args are non-dependent... */