From patchwork Tue Oct 30 23:44:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] PR 54583 Date: Tue, 30 Oct 2012 13:44:49 -0000 From: Paolo Carlini X-Patchwork-Id: 195664 Message-Id: <50906671.5050706@oracle.com> To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill Hi, this diagnostic issue is about spurious "value computed is not used" warnings with VLAs, emitted by convert_to_void (on the TYPE_SIZE, a MULT_EXPR): the warning is already gated by !TREE_NO_WARNING (expr) thus setting it at the end of build_cplus_array_type seems a rather straightforward fix. The below, which regtests fine, simply acts on any MULT_EXPR as TYPE_SIZE, which I think should be fine, but, in case the idea is basically Ok, we could also consider the more complex but more sophisticated variably_modified_type_p? Thanks, Paolo. ///////////////////// /cp 2012-10-30 Paolo Carlini PR c++/54583 * tree.c (build_cplus_array_type): Set TREE_NO_WARNING on the TYPE_SIZE of VLAs. /testsuite 2012-10-30 Paolo Carlini PR c++/54583 * g++.dg/ext/vla13.C: New. Index: testsuite/g++.dg/ext/vla13.C =================================================================== --- testsuite/g++.dg/ext/vla13.C (revision 0) +++ testsuite/g++.dg/ext/vla13.C (working copy) @@ -0,0 +1,8 @@ +// PR c++/54583 +// { dg-options "-Wunused-value" } + +void fred() +{ + int n=10; + double (*x)[n]; +} Index: cp/tree.c =================================================================== --- cp/tree.c (revision 192997) +++ cp/tree.c (working copy) @@ -824,6 +824,10 @@ build_cplus_array_type (tree elt_type, tree index_ } } + /* Avoid spurious warnings with VLAs (c++/54583). */ + if (TYPE_SIZE (t) && TREE_CODE (TYPE_SIZE (t)) == MULT_EXPR) + TREE_NO_WARNING (TYPE_SIZE (t)) = 1; + /* Push these needs up so that initialization takes place more easily. */ TYPE_NEEDS_CONSTRUCTING (t)