public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/34158]  New: Template delete doesn't call if exception thrown in constructor
@ 2007-11-20  3:50 andry at inbox dot ru
  2008-01-28  8:24 ` [Bug c++/34158] " andry at inbox dot ru
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: andry at inbox dot ru @ 2007-11-20  3:50 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-11-20  2:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
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

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).