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 c++/17648] [3.3 regression] template destructor was not called for inherited classes


------- Additional Comments From bangerth at dealii dot org  2004-09-24 13:01 -------
Nevermind, I see it now -- one has to actually run the test. 
 
So here is a reduced testcase: 
----------------------- 
#include <iostream> 
 
extern "C" void abort (); 
 
int counter = 0; 
template <class T> struct ListT { 
    ListT() { 
      ++counter; 
      std::cout << "constructor\n"; 
      array=NULL;  
    } 
 
    ~ListT() { 
      --counter; 
      std::cout << "destructor\n"; 
         
      if(array) 
        delete array; 
    } 
     
    T   *array; 
}; 
 
class Object; 
 
class ObjectList : public ListT<Object> {}; 
 
class Object { 
    ObjectList list; 
}; 
 
void test() { 
  Object Test; 
} 
 
int main() 
{ 
  test(); 
  if (counter != 0) 
    abort (); 
} 
---------------------------------- 
 
This works just fine with gcc 2.95.3, 3.2.3, 3.4.2 and mainline, but 
it fails with 3.3.4 for which we get only one call to the constructor 
but none for the destructor. 
 
The actual bug in the compiler seems to be rather sensitive to what is  
actually going on in ListT::~ListT. Maybe someone with more time on 
their hands can find a shorter testcase without includes. 
 
As for workarounds: if you move around some code, I can make the bug in 
the compiler go away. You may be able to achieve the same in your 
original code. Apart from that, many thanks for a nice and small testcase, 
even if I didn't see at first what the problem was :-( 
 
Thanks 
  Wolfgang 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |3.3.4
      Known to work|4.0.0                       |4.0.0 3.2.3 2.95.3 3.4.2
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-24 13:01:19
               date|                            |
            Summary|template destructor was not |[3.3 regression] template
                   |called for inherited classes|destructor was not called
                   |                            |for inherited classes
   Target Milestone|---                         |3.3.5


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


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