From patchwork Fri Jan 14 13:06:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 78899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 69056B6F10 for ; Sat, 15 Jan 2011 00:06:41 +1100 (EST) Received: (qmail 10179 invoked by alias); 14 Jan 2011 13:06:39 -0000 Received: (qmail 10169 invoked by uid 22791); 14 Jan 2011 13:06:39 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Jan 2011 13:06:35 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0ED6X2C016535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 14 Jan 2011 08:06:34 -0500 Received: from [127.0.0.1] (ovpn-113-138.phx2.redhat.com [10.3.113.138]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0ED6Xqi019710 for ; Fri, 14 Jan 2011 08:06:33 -0500 Message-ID: <4D304A58.5020301@redhat.com> Date: Fri, 14 Jan 2011 08:06:32 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/46688 (incorrect error with flexible array in constructor) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org build_vec_init_expr builds a single constructor call in order to mark the constructor as used and get any appropriate diagnostics. But in the case of a flexible array, initializing it won't actually call any constructors because it has no members, so we need to check for that case. Tested x86_64-pc-linux-gnu, applied to trunk. commit 30f32022b48840f117da0b5b9e75d8329cbd82e3 Author: Jason Merrill Date: Wed Jan 12 19:02:01 2011 -0500 PR c++/46688 * tree.c (build_vec_init_expr): Handle flexible array properly. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 213279a..813b88d 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -474,7 +474,12 @@ build_vec_init_expr (tree type, tree init) what functions are needed. Here we assume that init is either NULL_TREE, void_type_node (indicating value-initialization), or another array to copy. */ - if (init == void_type_node) + if (integer_zerop (array_type_nelts_total (type))) + { + /* No actual initialization to do. */; + init = NULL_TREE; + } + else if (init == void_type_node) { elt_init = build_value_init (inner_type, tf_warning_or_error); value_init = true; diff --git a/gcc/testsuite/g++.dg/ext/flexary2.C b/gcc/testsuite/g++.dg/ext/flexary2.C new file mode 100644 index 0000000..4855b3f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary2.C @@ -0,0 +1,11 @@ +// PR c++/46688 +// { dg-options "" } + +struct A { + A(int); +}; + +struct B { + B() {} + A a[]; +};