From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23922 invoked by alias); 24 Dec 2014 16:59:43 -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 23890 invoked by uid 48); 24 Dec 2014 16:59:38 -0000 From: "mw_triad at users dot sourceforge.net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/64399] g++ does not diagnose when upcasting owning pointer (e.g. unique_ptr) with non-virtual destructor Date: Wed, 24 Dec 2014 16:59:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: Message-ID: In-Reply-To: References: 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/msg02715.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64399 --- Comment #7 from Matthew Woehlke --- (In reply to Thiago Macieira from comment #3) > Because it's not a bug. > > This is a totally valid scenario. Valid in what way? I constructed a Y but arranged, probably by accident, that its dtor is never called. I fail to see how that's not likely a bug in my code that reasonably warrants a diagnostic. (Note that I'm talking about a *warning*, and possibly one that isn't even on by default, not an error.) (In reply to Marc Glisse from comment #6) > It might pedantically be illegal, but it is useful, and I believe some people > would like to avoid the warning when the two destructors are equivalent. However, the compiler doesn't know that here, because I didn't provided a definition thereof; Y's dtor, even in this example, could have important side effects. Even if the compiler *can* prove equivalence, I'd be suspicious whether this was intended, but I'd be okay with a different (i.e. more pedantic) warning in that case. (I'd also point out that it's not unreasonable to require the user to somehow annotate if this is intentional if they care about avoiding the warning when it's enabled.) Anyway, I still get no warning if Y has members that need to be destroyed, which definitely causes bad behavior when its dtor isn't called.