From patchwork Tue Feb 12 17:36:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 219922 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 E811E2C0089 for ; Wed, 13 Feb 2013 04:36:18 +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=1361295379; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=Nr2Mofu 1k1UY75bGTJl/tJ6XCyM=; b=vc2QGmDgBKr0BYLnXnaHMQeMmO9zl4uZXDWBNd4 mrc69xZ7iPR+Lp2PLqYXbWSwWALHsDvGIFtStohu2g2tFy7cUVw8E+xVEG+bWT6S Rav/xgkAsYZCJWM/Zw65ZeTXsjmOQdV5Dei5HSH8Nve/v+EotRPf+hcIFk2jb2Bu DSFk= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ecK0zmVD/ym6fW4JihzwCvOA/NXV+/KWGz5p1uBWi/ZZoO4h28OjGSi62moIV7 8m0xOOofMkgNaxvU4ezydn66cBtn/v0AMS8kg7E/mnclGMaofeXuXL646zbvlt5/ 9sLU1cpyhqtYYLWOYu4QqddodjK9GLe2eQeMvN6LJOmR0=; Received: (qmail 15388 invoked by alias); 12 Feb 2013 17:36:10 -0000 Received: (qmail 14951 invoked by uid 22791); 12 Feb 2013 17:36:07 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_VP 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; Tue, 12 Feb 2013 17:36:03 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1CHa3op004325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 12 Feb 2013 12:36:03 -0500 Received: from [10.3.113.67] (ovpn-113-67.phx2.redhat.com [10.3.113.67]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1CHa135005890 for ; Tue, 12 Feb 2013 12:36:02 -0500 Message-ID: <511A7D81.1090101@redhat.com> Date: Tue, 12 Feb 2013 12:36:01 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56291 (ICE with constexpr 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 When a class has all non-polymorphic bases but has virtual functions itself, its vtable pointer goes before the bases but is still initialized after them, so sort_constexpr_mem_initializers needs to handle this case as well. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 1e98e1cbcfd70b4ef013c3d8f046e9576d19e1ba Author: Jason Merrill Date: Tue Feb 12 12:02:58 2013 -0500 PR c++/56291 * semantics.c (sort_constexpr_mem_initializers): Handle vptr out of order. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e3dea09..e31ae30 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5948,31 +5948,39 @@ check_constexpr_ctor_body (tree last, tree list) /* V is a vector of constructor elements built up for the base and member initializers of a constructor for TYPE. They need to be in increasing offset order, which they might not be yet if TYPE has a primary base - which is not first in the base-clause. */ + which is not first in the base-clause or a vptr and at least one base + all of which are non-primary. */ static vec * sort_constexpr_mem_initializers (tree type, vec *v) { tree pri = CLASSTYPE_PRIMARY_BINFO (type); + tree field_type; constructor_elt elt; int i; - if (pri == NULL_TREE - || pri == BINFO_BASE_BINFO (TYPE_BINFO (type), 0)) + if (pri) + field_type = BINFO_TYPE (pri); + else if (TYPE_CONTAINS_VPTR_P (type)) + field_type = vtbl_ptr_type_node; + else return v; - /* Find the element for the primary base and move it to the beginning of - the vec. */ + /* Find the element for the primary base or vptr and move it to the + beginning of the vec. */ vec &vref = *v; - pri = BINFO_TYPE (pri); - for (i = 1; ; ++i) - if (TREE_TYPE (vref[i].index) == pri) + for (i = 0; ; ++i) + if (TREE_TYPE (vref[i].index) == field_type) break; - elt = vref[i]; - for (; i > 0; --i) - vref[i] = vref[i-1]; - vref[0] = elt; + if (i > 0) + { + elt = vref[i]; + for (; i > 0; --i) + vref[i] = vref[i-1]; + vref[0] = elt; + } + return v; } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C new file mode 100644 index 0000000..32cee96 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C @@ -0,0 +1,18 @@ +// PR c++/56291 +// { dg-options -std=c++11 } + +class Base +{ +public: + constexpr Base() : v(1) {}; + int v; +}; + +class Derived : public Base +{ +public: + constexpr Derived() : Base() {}; + virtual void function(); +}; + +Derived d;