From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21984 invoked by alias); 23 Dec 2014 22:58:22 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21963 invoked by uid 48); 23 Dec 2014 22:58:17 -0000 From: "mw_triad at users dot sourceforge.net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/64399] New: g++ does not diagnose when upcasting owning pointer (e.g. unique_ptr) with non-virtual destructor Date: Tue, 23 Dec 2014 22:58:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.8.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mw_triad at users dot sourceforge.net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-12/txt/msg02686.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64399 Bug ID: 64399 Summary: g++ does not diagnose when upcasting owning pointer (e.g. unique_ptr) with non-virtual destructor Product: gcc Version: 4.8.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: mw_triad at users dot sourceforge.net Consider the following code: #include struct X { ~X(); }; struct Y : X { ~Y(); }; std::unique_ptr f(); void g() { std::unique_ptr x = f(); } This code is almost certainly broken; ownership of the constructed Y is transferred to an owning unique_ptr in a way that will most likely (in general; "always" in this specific example) result in Y's destructor never being called. It seems pretty silly that there is no diagnostic for this. There ought to be a warning in unique_ptr's conversion operator converting from Derived to Base if ~Base is not virtual. (Arranging at the library level to trip -Wnon-virtual-dtor seems logical.)