From patchwork Thu Nov 17 15:40:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 126254 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 8CD19B7217 for ; Fri, 18 Nov 2011 02:40:59 +1100 (EST) Received: (qmail 23466 invoked by alias); 17 Nov 2011 15:40:55 -0000 Received: (qmail 23250 invoked by uid 22791); 17 Nov 2011 15:40:52 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Thu, 17 Nov 2011 15:40:32 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAHFeWdJ010094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 Nov 2011 10:40:32 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pAHFeWAq014495 for ; Thu, 17 Nov 2011 10:40:32 -0500 Received: from [0.0.0.0] (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pAHFeVLi003008 for ; Thu, 17 Nov 2011 10:40:31 -0500 Message-ID: <4EC52AEE.2050002@redhat.com> Date: Thu, 17 Nov 2011 10:40:30 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111112 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51137 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 My patch for 51029 fixed some virtual calls under fold_non_dependent_expr, but clearly not all. This patch goes farther. Tested x86_64-pc-linux-gnu, applying to trunk. commit 9c6ea6fd08c5c99ba4455b88bb8d0b0b6a71d171 Author: Jason Merrill Date: Tue Nov 15 14:27:04 2011 -0500 PR c++/51137 * class.c (build_base_path): Don't do calculation in templates. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4a291ac..0765817 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -304,8 +304,13 @@ build_base_path (enum tree_code code, virtual_access = (v_binfo && fixed_type_p <= 0); /* Don't bother with the calculations inside sizeof; they'll ICE if the - source type is incomplete and the pointer value doesn't matter. */ - if (cp_unevaluated_operand != 0) + source type is incomplete and the pointer value doesn't matter. In a + template (even in fold_non_dependent_expr), we don't have vtables set + up properly yet, and the value doesn't matter there either; we're just + interested in the result of overload resolution. */ + if (cp_unevaluated_operand != 0 + || (current_function_decl + && uses_template_parms (current_function_decl))) { expr = build_nop (ptr_target_type, expr); if (!want_pointer) @@ -359,11 +364,6 @@ build_base_path (enum tree_code code, V_BINFO. That offset is an entry in D_BINFO's vtable. */ tree v_offset; - /* In a constructor template, current_in_charge_parm isn't set, - and we might end up here via fold_non_dependent_expr. */ - if (fixed_type_p < 0 && !(cfun && current_in_charge_parm)) - fixed_type_p = 0; - if (fixed_type_p < 0 && in_base_initializer) { /* In a base member initializer, we cannot rely on the diff --git a/gcc/testsuite/g++.dg/template/virtual2.C b/gcc/testsuite/g++.dg/template/virtual2.C new file mode 100644 index 0000000..83b7ed6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/virtual2.C @@ -0,0 +1,11 @@ +// PR c++/51137 + +struct A {}; + +template struct B : virtual A +{ + void foo() + { + (new A(*this))->A::~A(); + } +};