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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  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 ` andry at inbox dot ru
  2008-05-15 14:11 ` andry at inbox dot ru
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: andry at inbox dot ru @ 2008-01-28  8:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from andry at inbox dot ru  2008-01-28 02:46 -------
In gcc 4.3 (trunk, 2008.01.27), bug still doesn't fixed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: andry at inbox dot ru @ 2008-05-15 14:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from andry at inbox dot ru  2008-05-15 14:10 -------
Version 4.3.0 (Release), bug still doesn't fixed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steve_cheng at scotiacapital dot com @ 2008-05-23 13:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from steve_cheng at scotiacapital dot com  2008-05-23 13:41 -------
I have hit the same bug as the original reporter.  
Attached is a simplified test case.  Run with:

$ g++ -v -save-temps -o testPlacementDelete testPlacementDelete.C 
$ ./testPlacementDelete
placement new called
exception caught

Expected output should be instead:
placement new called
placement delete called
exception caught

Note that the placement delete is called if the extra argument to placement new
and delete is a non-templated type.  It fails when the extra argument is a
templated type.

I am running on:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1
--enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug
--enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
 /usr/lib/gcc/i486-linux-gnu/4.1.3/cc1plus -E -quiet -v -D_GNU_SOURCE
testPlacementDelete.C -mtune=generic -fpch-preprocess -o testPlacementDelete.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.1.3
 /usr/include/c++/4.1.3/i486-linux-gnu
 /usr/include/c++/4.1.3/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.1.3/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.1.3/cc1plus -fpreprocessed
testPlacementDelete.ii -quiet -dumpbase testPlacementDelete.C -mtune=generic
-auxbase testPlacementDelete -version -fstack-protector -fstack-protector -o
testPlacementDelete.s
GNU C++ version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
(i486-linux-gnu)
        compiled by GNU C version 4.1.3 20070929 (prerelease) (Ubuntu
4.1.2-16ubuntu2).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129322
Compiler executable checksum: 3cc47be363985179cfafdceddd0e8f5d
 as --traditional-format -V -Qy -o testPlacementDelete.o testPlacementDelete.s
GNU assembler version 2.18 (i486-linux-gnu) using BFD version (GNU Binutils for
Ubuntu) 2.18
 /usr/lib/gcc/i486-linux-gnu/4.1.3/collect2 --eh-frame-hdr -m elf_i386
--hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o testPlacementDelete
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.1.3 -L/usr/lib/gcc/i486-linux-gnu/4.1.3
-L/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib -L/lib/../lib
-L/usr/lib/../lib testPlacementDelete.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s
-lgcc /usr/lib/gcc/i486-linux-gnu/4.1.3/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crtn.o


-- 

steve_cheng at scotiacapital dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steve_cheng at scotiacapital
                   |                            |dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steve_cheng at scotiacapital dot com @ 2008-05-23 13:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from steve_cheng at scotiacapital dot com  2008-05-23 13:43 -------
Created an attachment (id=15676)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15676&action=view)
C++ test case


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steve_cheng at scotiacapital dot com @ 2008-05-23 13:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from steve_cheng at scotiacapital dot com  2008-05-23 13:44 -------
Created an attachment (id=15677)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15677&action=view)
-save-temps when compiling C++ testcase


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2008-11-01 16:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jwakely dot gcc at gmail dot com  2008-11-01 16:18 -------
This is a compile-time test which should fail because undef<T> cannot be
instantiated, but the deallocation function is not used.

#include <stdlib.h>

template <class T> class undef;

struct A {
  A() { throw 1; }
};

template<typename T> class Pool { };

template<typename T>
inline void *operator new(size_t size,Pool<T>& pool)
{
  return malloc(size);
}

template<typename T>
inline void operator delete(void *p,Pool<T>& pool)
{
  undef<T> t;
  free(p);
}

int main ()
{
  Pool<int> pool;
  new (pool) A();
  return 0;
}


-- 

jwakely dot gcc at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jwakely dot gcc at gmail dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-10  3:47 UTC (permalink / raw)
  To: gcc-bugs



-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-11-10 03:47:06
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-10 18:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2009-11-10 18:19 -------
Subject: Bug 34158

Author: jason
Date: Tue Nov 10 18:18:51 2009
New Revision: 154072

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154072
Log:
        PR c++/34158
        PR c++/36406
        * call.c (non_placement_deallocation_fn_p): Split out...
        (build_op_delete_call): ...from here.  Use instantiate_type
        for placement delete.  Simplify logic.
        * pt.c (primary_template_instantiation_p): Non-static.
        * cp-tree.h: Declare it.

Added:
    trunk/gcc/testsuite/g++.dg/init/placement4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-20  2:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2009-11-20 02:31 -------
Fixed


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34158


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

* [Bug c++/34158] Template delete doesn't call if exception thrown in constructor
  2007-11-20  3:50 [Bug c++/34158] New: Template delete doesn't call if exception thrown in constructor andry at inbox dot ru
                   ` (8 preceding siblings ...)
  2009-11-20  2:32 ` jason at gcc dot gnu dot org
@ 2009-11-20  2:37 ` jason at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-20  2:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jason at gcc dot gnu dot org  2009-11-20 02:37 -------
.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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