From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13054 invoked by alias); 16 Jan 2013 19:58:23 -0000 Received: (qmail 12982 invoked by uid 48); 16 Jan 2013 19:58:02 -0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56009] New: Nested global destruction semantics not working (mingw) Date: Wed, 16 Jan 2013 19:58: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: daniel.kruegler at googlemail 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: 2013-01/txt/msg01567.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56009 Bug #: 56009 Summary: Nested global destruction semantics not working (mingw) Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: daniel.kruegler@googlemail.com The following program - compiled with flags -Wall -pedantic-errors produces an unexpected output: //----------------------------------- extern "C" int printf(const char *, ...); class A { A(const A&); A& operator=(const A&); A() { printf("A()\n"); } ~A() { printf("~A()\n"); } public: void use() { printf("A is here!\n"); } static A& get_instance() { static A result; return result; } }; void use_A(const char* message) { A& a = A::get_instance(); printf("Using A %s\n", message); a.use(); } struct B { ~B() { use_A("from ~B()"); } } b; int main() {} //----------------------------------- A() Using A from ~B() A is here! Note the lack of the expected last line: ~A() Some further characteristics: 1) The problem is observed on a mingw-64bit system (Windows 7). I have been told that the problem doesn't occur on Linux(?) systems (Thanks to Jonathan Wakely) 2) The kind of global destruction semantics doesn't matter: Instead of a local static variables we can use corresponding series of nested atexit() registrations. 3) The problem is not related to flushing: Replacement of above printf calls by e.g. std::cout with an effective std::flush call doesn't change anything