From patchwork Thu May 26 18:30:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] PR 42056 X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 97609 Message-Id: <4DDE9C50.7050601@oracle.com> To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill Date: Thu, 26 May 2011 20:30:40 +0200 From: Paolo Carlini List-Id: Hi, I have just regtested on x86_64-linux the below patchlet for a simple accepts-invalid, exploiting type_uses_auto, as suggested by Jason. We want to do that only when processing a template, because otherwise we get a duplicate diagnostic, see, eg, auto9.C; also, not returning error_mark_node unconditionally, means a better diagnostic, without redundant "array bound is not an integer constant before...". As for the error message itself, I'm just emitting what we otherwise emit outside templates... Ok? Thanks, Paolo. /////////////////// /cp 2011-05-26 Paolo Carlini PR c++/42056 * typeck2.c (build_functional_cast): When processing_template_decl, check for invalid uses of 'auto'. /testsuite 2011-05-26 Paolo Carlini PR c++/42056 * testsuite/g++.dg/cpp0x/auto25.C: New. * testsuite/g++.dg/cpp0x/auto26.C: Likewise. 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 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 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 %"); + 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... */