public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "andry at inbox dot ru" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor Date: Tue, 20 Nov 2007 03:50:00 -0000 [thread overview] Message-ID: <bug-34158-15391@http.gcc.gnu.org/bugzilla/> (raw) I recently have been discovered some issue on gcc 4.1.2. Here is my system: OS: Intel-P4,WindowXP+SP2 Cygwin: Setup.exe version 2.573.2.2 config.status: "./configure --enable-languages=c,c++,java,objc" Command line: g++ test.cpp > a 2> b Minimal example (test.cpp): /////////////////////////////////////////////////////////////////////////////// #include <new> #include <stdio.h> //dummy... template<class T1> class TAlignedMem {}; struct A1 { A1() { throw 0; } }; //throwing in ctor unsigned char* pAlloc1 = 0; //Some user new template<class T> void* operator new(size_t n,TAlignedMem<T>) /*throw()*/ { unsigned char*const pRawMemory = pAlloc1 = reinterpret_cast<unsigned char*>(operator new(n+32)); for(int i = 0; i < 32; i++) { pRawMemory[i] = 0xCC; } printf("user new\n"); return pRawMemory+32; } void DumpBlock(void* p) { if(!p) return; unsigned char*const pRawMemoryWithOffset = reinterpret_cast<unsigned char*>(p); unsigned char*const pRawMemory = pRawMemoryWithOffset-32; for(int i = 0; i < 32/4; i++) { printf("0x%08X ",((unsigned int*)pRawMemory)[i]); } printf("\n"); } //Some user delete template<class T> void operator delete(void* p,TAlignedMem<T>) /*throw()*/ { unsigned char*const pRawMemoryWithOffset = reinterpret_cast<unsigned char*>(p); unsigned char*const pRawMemory = pRawMemoryWithOffset-32; printf("user delete: "); DumpBlock(p); operator delete(pRawMemory); } int main() { A1* p1 = 0; try { p1 = new ((TAlignedMem<A1>())) A1; } catch(...) { printf("catch(...)\n"); } printf("dumped block: "); DumpBlock(pAlloc1); return 0; } /////////////////////////////////////////////////////////////////////////////// a.exe output: /////////////////////////////////////////////////////////////////////////////// user new catch(...) dumped block: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x0000002B /////////////////////////////////////////////////////////////////////////////// If you try correct code from here: /////////////////////////////////////////////////////////////////////////////// //Some user delete template<class T> void operator delete(void* p,TAlignedMem<T>) /*throw()*/ { /////////////////////////////////////////////////////////////////////////////// To this one: /////////////////////////////////////////////////////////////////////////////// //Some user delete void operator delete(void* p,TAlignedMem<A1>) /*throw()*/ { /////////////////////////////////////////////////////////////////////////////// And try run again: /////////////////////////////////////////////////////////////////////////////// user new user delete: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC catch(...) dumped block: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000061 /////////////////////////////////////////////////////////////////////////////// "delete" will call successfully. -- Summary: Template delete doesn't call if exception thrown in constructor Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: andry at inbox dot ru http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158
next reply other threads:[~2007-11-20 3:50 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-11-20 3:50 andry at inbox dot ru [this message] 2008-01-28 8:24 ` [Bug c++/34158] " andry at inbox dot ru 2008-05-15 14:11 ` andry at inbox dot ru 2008-05-23 13:42 ` steve_cheng at scotiacapital dot com 2008-05-23 13:44 ` steve_cheng at scotiacapital dot com 2008-05-23 13:45 ` steve_cheng at scotiacapital dot com 2008-11-01 16:19 ` jwakely dot gcc at gmail dot com 2009-11-10 3:47 ` jason at gcc dot gnu dot org 2009-11-10 18:19 ` jason at gcc dot gnu dot org 2009-11-20 2:32 ` jason at gcc dot gnu dot org 2009-11-20 2:37 ` jason at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-34158-15391@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).