|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2000-12-06 00:21:35
> Shared_array isn't the answer here. Slawomir was correct to use
> shared_ptr, since the smart pointer is pointing to a scalar. His code
> has smart pointer object itself stored in an array. I couldn't find
oops...should have read the code.
> any problem with the code. I wish I could be more helpful. It seems
> like a compiler bug,
With GCC2.95.2 the destructors for array's of template classes never get
run. Normal classes are fine. No exceptions are required to create the
problem. Note that if the bar_array is moved to main the destructors are
run. The following is a simplified version of Slawomir's problem for
GCC2.95.2.
#include <iostream>
class foo
{
public:
foo() {std::cout << "foo construct" << std::endl;}
~foo() {std::cout << "foo destruct" << std::endl;}
};
template<class T>
class bar {
public:
bar() {std::cout << "bar construct" << std::endl;};
~bar() {std::cout << "bar destruct" << std::endl;};
} ;
void f()
{
foo foo_array[] = {foo(),foo()}; //destructors run on return
bar<int> bar_array[] = {bar<int>(), bar<int>()}; //oops...destructors
never run with gcc
}
int
main()
{
f();
}
With Borland 5.5 the bug is more subtle. At least 2 arrays are needed in
the function and templates don't matter. An exception must be thrown for
the problem to occur.
> but imagine the odds of that: 2 or of 3 compilers
> are non-conformant and VC isn't among them! :-]
Makes you believe in miracles :)
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk