From patchwork Wed Apr 1 10:08:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 457204 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1DB801400A0 for ; Wed, 1 Apr 2015 21:08:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=YE1hJNaw; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=lLTNBoeTVrIW65r5T DYAzMyotv/573QfCgtntjNdnkvg2eGh/NqGCpb+RLUdnUXIei0N8yxrLGddx3Bdq EW/2vn700sS77BpwKdtJXoBG6R6iKVZGwPV67aN9J07ND24Wxira7KIym5PQA2fu 43bT95HZuFHPPrRwcDCZZgtKdY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=orJsYwaAp0L5fF1f/FfvwYn LNP4=; b=YE1hJNawZDgJc2t1SHAHfZPaQ1JOCtGeYGeFeYD9O192L/bPzx3Fmfc 68oKsuwzLkLR8OLcjdDxUjXuIV5WATcz9/sDFgTi0MrO0XcsNBnu4IlCUCw8p4bt Li59tlKbw5UpzAeB2RDFUjXjigsC2i0Nn7Dq3LjaBAigp2R/nzWE= Received: (qmail 127784 invoked by alias); 1 Apr 2015 10:08:25 -0000 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 Received: (qmail 127771 invoked by uid 89); 1 Apr 2015 10:08:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 01 Apr 2015 10:08:23 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id C80558E79F for ; Wed, 1 Apr 2015 10:08:21 +0000 (UTC) Received: from redhat.com (ovpn-204-20.brq.redhat.com [10.40.204.20]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t31A8H7H025468 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Wed, 1 Apr 2015 06:08:19 -0400 Date: Wed, 1 Apr 2015 12:08:16 +0200 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: C++ PATCH for c++/65554 (ICE with user-defined initializer_list) Message-ID: <20150401100816.GQ25731@redhat.com> References: <20150331172253.GP25731@redhat.com> <551AF15C.20200@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <551AF15C.20200@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) On Tue, Mar 31, 2015 at 03:11:24PM -0400, Jason Merrill wrote: > On 03/31/2015 01:22 PM, Marek Polacek wrote: > >The user *should* have been using . But responding to this > >with an ICE isn't acceptable either. > > > >We do reject wholly incompatible user-defined initializer_list: finish_struct > >requires it be a template with a pointer field followed by an integer field, > >and in this case it is, but convert_like_real assumes that the second integer > >field has a size_type, so it initializes the length with that type. But as the > >following testcase (which clang accepts) shows, it might be a different integer > >type, and gimplifier doesn't like any non-trivial conversion in an assignment. > > I think I'd prefer to enforce that the second integer is size_t, not just an > integer, so that the assumption in convert_like_real is correct. Ok, that isn't hard to do either. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-04-01 Marek Polacek PR c++/65554 * class.c (finish_struct): Require that the second field of a user-defined initializer_list be of size type. * g++.dg/cpp0x/initlist93.C: New test. * g++.dg/cpp0x/initlist94.C: New test. Marek diff --git gcc/cp/class.c gcc/cp/class.c index c2d4201..9f189fb 100644 --- gcc/cp/class.c +++ gcc/cp/class.c @@ -6891,7 +6891,7 @@ finish_struct (tree t, tree attributes) if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE) { f = next_initializable_field (DECL_CHAIN (f)); - if (f && TREE_CODE (TREE_TYPE (f)) == INTEGER_TYPE) + if (f && same_type_p (TREE_TYPE (f), size_type_node)) ok = true; } } diff --git gcc/testsuite/g++.dg/cpp0x/initlist93.C gcc/testsuite/g++.dg/cpp0x/initlist93.C index e69de29..84a4738 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist93.C +++ gcc/testsuite/g++.dg/cpp0x/initlist93.C @@ -0,0 +1,13 @@ +// PR c++/65554 +// { dg-do compile { target c++11 } } + +namespace std +{ +template class initializer_list // { dg-error "definition of std::initializer_list does not match" } +{ + int *_M_array; + int _M_len; +}; +} + +// { dg-prune-output "compilation terminated" } diff --git gcc/testsuite/g++.dg/cpp0x/initlist94.C gcc/testsuite/g++.dg/cpp0x/initlist94.C index e69de29..f83a81d 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist94.C +++ gcc/testsuite/g++.dg/cpp0x/initlist94.C @@ -0,0 +1,13 @@ +// PR c++/65554 +// { dg-do compile { target c++11 } } + +typedef decltype (sizeof (int)) size_type; + +namespace std +{ +template class initializer_list +{ + int *_M_array; + size_type _M_len; +}; +}