From patchwork Fri Jul 1 19:55:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 102963 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 EE6D5B6F5C for ; Sat, 2 Jul 2011 05:56:15 +1000 (EST) Received: (qmail 28488 invoked by alias); 1 Jul 2011 19:56:09 -0000 Received: (qmail 28478 invoked by uid 22791); 1 Jul 2011 19:56:07 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_NV X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 19:55:52 +0000 Received: by pzk36 with SMTP id 36so1032996pzk.20 for ; Fri, 01 Jul 2011 12:55:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.250.29 with SMTP id x29mr1570812wfh.21.1309550152215; Fri, 01 Jul 2011 12:55:52 -0700 (PDT) Received: by 10.143.4.7 with HTTP; Fri, 1 Jul 2011 12:55:51 -0700 (PDT) Date: Fri, 1 Jul 2011 20:55:51 +0100 Message-ID: Subject: [patch] fix c++/49605: -Wdelete-non-virtual-dtor is not picky enough From: Jonathan Wakely To: gcc-patches Cc: Jason Merrill 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 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49605 There's a spurious warning because I didn't realise that build_delete is used for destroying automatic variables as well as for delete expression, this fixes it by checking for sfk_deleting_destructor, is that the right thing to do? Tested x86_64-linux, ok for trunk? Or would it be better to move this warning further down, with these other things that only apply to sfk_deleting_destrutor? if (use_global_delete && auto_delete == sfk_deleting_destructor) ... else if (!DECL_VIRTUAL_P (CLASSTYPE_DESTRUCTORS (type)) && auto_delete == sfk_deleting_destructor) ... else if (auto_delete == sfk_deleting_destructor && TYPE_GETS_REG_DELETE (type)) cp/ChangeLog PR c++/49065 * init.c (build_delete): Only warn for sfk_deleting_destructor. testsuite/ChangeLog PR c++/49065 * g++.dg/warn/delete-non-virtual-dtor.C: Adjust. Index: cp/init.c =================================================================== --- cp/init.c (revision 175752) +++ cp/init.c (working copy) @@ -3467,8 +3467,9 @@ } complete_p = false; } - else if (warn_delnonvdtor && MAYBE_CLASS_TYPE_P (type) - && !CLASSTYPE_FINAL (type) && TYPE_POLYMORPHIC_P (type)) + else if (auto_delete == sfk_deleting_destructor && warn_delnonvdtor + && MAYBE_CLASS_TYPE_P (type) && !CLASSTYPE_FINAL (type) + && TYPE_POLYMORPHIC_P (type)) { tree dtor; dtor = CLASSTYPE_DESTRUCTORS (type); Index: testsuite/g++.dg/warn/delete-non-virtual-dtor.C =================================================================== --- testsuite/g++.dg/warn/delete-non-virtual-dtor.C (revision 175752) +++ testsuite/g++.dg/warn/delete-non-virtual-dtor.C (working copy) @@ -5,6 +5,7 @@ void f(polyBase* p, polyBase* arr) { + polyBase pb; delete p; // { dg-warning "non-virtual destructor might" } delete [] arr; } @@ -13,6 +14,7 @@ void f(polyDerived* p, polyDerived* arr) { + polyDerived pd; delete p; // { dg-warning "non-virtual destructor might" } delete [] arr; } @@ -29,6 +31,7 @@ void f(finalDerived* p, finalDerived* arr) { + finalDerived fd; delete p; // no error for final classes delete [] arr; } @@ -38,7 +41,26 @@ void f(safeDerived* p, safeDerived* arr) { + safeDerived sd; delete p; // no error because base has virtual dtor delete [] arr; } +struct polyBaseNonTrivial { ~polyBaseNonTrivial(); virtual void f(); }; + +void f(polyBaseNonTrivial* p, polyBaseNonTrivial* arr) +{ + polyBaseNonTrivial pbnt; + delete p; // { dg-warning "non-virtual destructor might" } + delete [] arr; +} + +struct polyDerivedNT : polyBaseNonTrivial { ~polyDerivedNT(); }; + +void f(polyDerivedNT* p, polyDerivedNT* arr) +{ + polyDerivedNT pdnt; + delete p; // { dg-warning "non-virtual destructor might" } + delete [] arr; +} +