This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor
- From: "andry at inbox dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Nov 2007 03:50:06 -0000
- Subject: [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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