From patchwork Mon May 2 10:44:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 93628 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 B771FB6F80 for ; Mon, 2 May 2011 20:45:13 +1000 (EST) Received: (qmail 29269 invoked by alias); 2 May 2011 10:45:11 -0000 Received: (qmail 29256 invoked by uid 22791); 2 May 2011 10:45:10 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet10.oracle.com (HELO rcsinet10.oracle.com) (148.87.113.121) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 May 2011 10:44:56 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p42AisDr031664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 May 2011 10:44:55 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p42AirDb024231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 2 May 2011 10:44:53 GMT Received: from abhmt005.oracle.com (abhmt005.oracle.com [141.146.116.14]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p42AimH7007971; Mon, 2 May 2011 05:44:48 -0500 Received: from [192.168.1.4] (/79.47.194.175) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 02 May 2011 03:44:47 -0700 Message-ID: <4DBE8AFE.2060906@oracle.com> Date: Mon, 02 May 2011 12:44:15 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 47969 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, we have this simple issue where we ICE because we don't check the return value of build_expr_type_conversion for NULL_TREE, at variance with all its other uses elsewhere. The fix seems also simple, we have already logic for emitting an error message (or just returning error_mark_node depending on complain) in case of non-integral size of the array, only, a bit later. Thus my fix, adding a goto. If we don't like that, we could do the below, which just duplicated the logic. All in all, barring completely different solutions, which I don't see at the moment, the goto seems to me a tad better. Tested x86_64-linux. Ok for mainline? Paolo. ///////////////// /cp 2011-05-02 Paolo Carlini PR c++/47969 * decl.c (compute_array_index_type): Check build_expr_type_conversion return value for NULL_TREE. /testsuite 2011-05-02 Paolo Carlini PR c++/47969 * g++.dg/cpp0x/constexpr-47969.C: New. Index: testsuite/g++.dg/cpp0x/constexpr-47969.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-47969.C (revision 0) +++ testsuite/g++.dg/cpp0x/constexpr-47969.C (revision 0) @@ -0,0 +1,11 @@ +// PR c++/47969 +// { dg-options -std=c++0x } + +struct A +{ + // constexpr operator int () { return 1; } +}; + +constexpr A a = A(); + +int ar[a]; // { dg-error "has non-integral type" } Index: cp/decl.c =================================================================== --- cp/decl.c (revision 173242) +++ cp/decl.c (working copy) @@ -7609,6 +7609,8 @@ compute_array_index_type (tree name, tree size, ts && CLASSTYPE_LITERAL_P (type)) { size = build_expr_type_conversion (WANT_INT, size, true); + if (!size) + goto error; if (size == error_mark_node) return error_mark_node; type = TREE_TYPE (size); @@ -7625,6 +7627,7 @@ compute_array_index_type (tree name, tree size, ts if (error_operand_p (size)) return error_mark_node; + error: /* The array bound must be an integer type. */ if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) { Index: cp/decl.c =================================================================== --- cp/decl.c (revision 173242) +++ cp/decl.c (working copy) @@ -7609,6 +7609,17 @@ compute_array_index_type (tree name, tree size, ts && CLASSTYPE_LITERAL_P (type)) { size = build_expr_type_conversion (WANT_INT, size, true); + if (!size) + { + if (!(complain & tf_error)) + return error_mark_node; + if (name) + error ("size of array %qD has non-integral type %qT", + name, type); + else + error ("size of array has non-integral type %qT", type); + size = integer_one_node; + } if (size == error_mark_node) return error_mark_node; type = TREE_TYPE (size);