This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/16115] [3.5 regression] double-destruction problem with argument passing via temporary (breaks auto_ptr)


------- Additional Comments From bangerth at dealii dot org  2004-06-21 18:26 -------
Here's a reduced testcase: 
--------------------- 
extern "C" void abort(); 
 
int count = 0; 
 
struct T { 
    T() { count++; } 
    T(const T&) { count++; } 
    ~T() { if (count==0) abort(); --count; } 
}; 
 
struct auto_ptr { 
    T* p; 
 
    auto_ptr(T* __p) : p(__p) { } 
    ~auto_ptr() { delete p; } 
 
    T* release() { 
      T* t = p; 
      p = 0; 
      return t; 
    } 
}; 
 
void destroy (auto_ptr a) { 
  delete a.release(); 
} 
 
 
int main () 
{ 
  destroy (new T); 
} 
----------------------------- 
 
For this, I get 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ x.cc -O2 && ./a.out  
Aborted 
 
We indeed call operator delete twice, once inside destroy, and once 
inside the destructor of the argument to destroy. However, since release 
sets p=0, the second time we call operator delete we shouldn't get a call 
to the destructor of class T. Alas, we do, thus the abort. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[3.5 regression] problem    |[3.5 regression] double-
                   |with argument passing via   |destruction problem with
                   |temporary (breaks auto_ptr) |argument passing via
                   |                            |temporary (breaks auto_ptr)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]