From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14626 invoked by alias); 23 Nov 2012 20:42:04 -0000 Received: (qmail 14518 invoked by uid 48); 23 Nov 2012 20:41:48 -0000 From: "blitzmunter at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55453] New: Bug with virtual methods and objects with dtors. Date: Fri, 23 Nov 2012 20:42:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: blitzmunter at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-11/txt/msg02212.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55453 Bug #: 55453 Summary: Bug with virtual methods and objects with dtors. Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: blitzmunter@gmail.com Hi, Mingw G++ appears to have a bug involving multiple inheritance and virtual methods that return objects with dtors. I have tried on 3 ditros - nuwen, tdm and the official mingw distro - and it happens on all g++ versions >= 4.7.0. It does not appear to occur on Linux, although I've only been able to test with kubuntu12 and mint14, both of which have g++ 4.7.2 installed. Even though this appears to be mingw specific, I've already posted this bug report on the mingw bug reports system and they told me to post it here. Anyway, see below code: The problem occurs when the 'interface method' LinkResolver is called by the markdown object. The correct method is invoked, but the 'this' pointer is messed up. The trigger seems to be the String dtor. Remove this, or have the interface method return a simple type, and it works as expected. Bye! Mark //***** CODE ****** #include struct String { ~String() { } }; struct Object { virtual ~Object() { } }; struct LinkResolver { virtual String ResolveLink() = 0; }; struct Docs : public Object, public virtual LinkResolver { Docs() { printf(" Docs::Docs() this: %p\n", this); } virtual String ResolveLink() { printf("Docs::ResolveLink() this: %p\n", this); return String(); } }; struct Markdown { LinkResolver * _resolver; Markdown(LinkResolver * resolver) : _resolver(resolver) { } void Go() { _resolver->ResolveLink(); } }; int main() { printf("GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); Docs d; printf(" main() &d: %p\n", &d); d.ResolveLink(); Markdown m(&d); m.Go(); }