From patchwork Thu Nov 10 21:12:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 125004 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 EDA2CB6F7C for ; Fri, 11 Nov 2011 08:13:08 +1100 (EST) Received: (qmail 14142 invoked by alias); 10 Nov 2011 21:13:05 -0000 Received: (qmail 14131 invoked by uid 22791); 10 Nov 2011 21:13:04 -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, 10 Nov 2011 21:12:47 +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 pAALCkab027477 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 10 Nov 2011 16:12:46 -0500 Received: from [127.0.0.1] (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pAALCkXB014982 for ; Thu, 10 Nov 2011 16:12:46 -0500 Message-ID: <4EBC3E4D.2090301@redhat.com> Date: Thu, 10 Nov 2011 16:12:45 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50973 (ICE with defaulted virtual destructor) 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 Here the problem was that we were calling use_thunk before we knew what the right linkage for the function it's thunking to was. Fixed by deferring synthesis of virtual dtors until EOF. Tested x86_64-pc-linux-gnu, applying to trunk. commit 566d5469261e63f8359998386b3b7c60ecd5e2ba Author: Jason Merrill Date: Wed Nov 9 15:53:04 2011 -0500 PR c++/50973 * decl2.c (mark_used): Defer synthesis of virtual functions. * method.c (use_thunk): Make sure the target function has DECL_INTERFACE_KNOWN. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 4e24755..05f4b42 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -4347,6 +4347,14 @@ mark_used (tree decl) && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl) && ! DECL_INITIAL (decl)) { + /* Defer virtual destructors so that thunks get the right + linkage. */ + if (DECL_VIRTUAL_P (decl) && !at_eof) + { + note_vague_linkage_fn (decl); + return true; + } + /* Remember the current location for a function we will end up synthesizing. Then we can inform the user where it was required in the case of error. */ @@ -4358,7 +4366,7 @@ mark_used (tree decl) on the stack (such as overload resolution candidates). We could just let cp_write_global_declarations handle synthesizing - this function, since we just added it to deferred_fns, but doing + this function by adding it to deferred_fns, but doing it at the use site produces better error messages. */ ++function_depth; synthesize_method (decl); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index bb58312..8101f8a 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -339,6 +339,7 @@ use_thunk (tree thunk_fndecl, bool emit_p) DECL_EXTERNAL (thunk_fndecl) = 0; /* The linkage of the function may have changed. FIXME in linkage rewrite. */ + gcc_assert (DECL_INTERFACE_KNOWN (function)); TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function); DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function); DECL_VISIBILITY_SPECIFIED (thunk_fndecl) diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted33.C b/gcc/testsuite/g++.dg/cpp0x/defaulted33.C new file mode 100644 index 0000000..2f11c13 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted33.C @@ -0,0 +1,32 @@ +// PR c++/50973 +// { dg-do compile { target c++11 } } + +class HD +{ + public: + virtual ~HD() {}; +}; +class InputHD : public virtual HD +{ +}; +class OutputHD : public virtual HD +{ +}; +class IOHD : public InputHD, public OutputHD +{ +}; +template +class ArrayNHD : public IOHD +{ + public: + ~ArrayNHD() = default; +}; +class TLText +{ + ~TLText(); + ArrayNHD* m_argsHD; +}; +TLText::~TLText() +{ + delete m_argsHD; +}