From patchwork Wed Oct 17 15:40:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 192077 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 CCE692C0084 for ; Thu, 18 Oct 2012 02:40:59 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1351093260; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=V3UwdtT7KWmzVfpyRCYPrcoM9xo=; b=mnTJMhMkQFZyn9C QRMw8WB91UHSZPBGM3MN7VbWRn2rd6IYhp8pIqCyiJHDoi6D7dXoHhlZAnT43pFY 5u7kSsK8zAsw4kyVd0Y7OyPd9CbczNlQojm23Iqoscal6x/kjsJMfO4FH69yaUix BEbblXT9h0W1jj4MgQ7xVCYBQhTU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=hHD9lPlSZu6mhe54e3D6u0avNm1JFdgstT2GRQGLmnji67J3NDcmNqGgzTB5O+ J1Qhm1qiEl5CtsaUN0+nIZVzLrAPHawXmOiL4B+TpwZjyEWshwGN68gaF9xCavAb tXQ1SPRlTj7Ws+zoVhOEcLmgTNB2MTJ4ZaqETJtfHbFEo=; Received: (qmail 16399 invoked by alias); 17 Oct 2012 15:40:56 -0000 Received: (qmail 16388 invoked by uid 22791); 17 Oct 2012 15:40:55 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 17 Oct 2012 15:40:49 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9HFelF0029347 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 17 Oct 2012 15:40:48 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9HFekdx008614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 17 Oct 2012 15:40:46 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9HFejlY008651; Wed, 17 Oct 2012 10:40:46 -0500 Received: from [192.168.1.4] (/79.36.29.35) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2012 08:40:45 -0700 Message-ID: <507ED17B.7080505@oracle.com> Date: Wed, 17 Oct 2012 17:40:43 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 54501 X-IsSubscribed: yes 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 Hi, for this kind of code, using the GNU zero-size array extension: int a[][0] = {0}; we end up looping forever in the reshape_init_array_1 loop because it calls reshape_init_r -> reshape_init_array -> reshape_init_array_1 which returns early a CONSTRUCTOR with no error. Having considered various solutions, I'm proposing to break the endless loop in reshape_init_array, where we have information about the type of the zero-size array and we can easily provide an accurate error message. Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2012-10-17 Paolo Carlini PR c++/54501 * decl.c (reshape_init_array): Check for zero-size arrays. /testsuite 2012-10-17 Paolo Carlini PR c++/54501 * g++.dg/init/array30.C: New. * g++.dg/init/array0.C: Adjust. * g++.dg/parse/pr43765.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 192527) +++ cp/decl.c (working copy) @@ -5068,6 +5068,13 @@ reshape_init_array (tree type, reshape_iter *d, ts if (TYPE_DOMAIN (type)) max_index = array_type_nelts (type); + if (max_index && integer_all_onesp (max_index)) + { + if (complain & tf_error) + error ("initializers provided for zero-size array of type %qT", type); + return error_mark_node; + } + return reshape_init_array_1 (TREE_TYPE (type), max_index, d, complain); } Index: testsuite/g++.dg/init/array0.C =================================================================== --- testsuite/g++.dg/init/array0.C (revision 192527) +++ testsuite/g++.dg/init/array0.C (working copy) @@ -8,5 +8,5 @@ void foo() unsigned char dir; int data[0]; } yanito; - static const yanito horse = { 1, { 2, 3 } }; // { dg-error "too many" } + static const yanito horse = { 1, { 2, 3 } }; // { dg-error "zero-size" } } Index: testsuite/g++.dg/init/array30.C =================================================================== --- testsuite/g++.dg/init/array30.C (revision 0) +++ testsuite/g++.dg/init/array30.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/54501 +// { dg-options "" } + +int main() +{ + int a[][0] = {0}; // { dg-error "zero-size" } +} Index: testsuite/g++.dg/parse/pr43765.C =================================================================== --- testsuite/g++.dg/parse/pr43765.C (revision 192527) +++ testsuite/g++.dg/parse/pr43765.C (working copy) @@ -11,4 +11,4 @@ SomeType vals[] = { { values : temp, }, 0 - }; // { dg-error "invalid" } + }; // { dg-error "zero-size" }