Basically I have a strange problem, I have a struct Node that inherits from counter struct. And in the counter struct I have this check to make “sure” that Destructor is called only on allocated memory and that it is called only once.
static atomic < int > check;
counter()
{
check=42;
//...
}
~counter()
{
if (check!=42)
{
cout<<"ouch"<< typeid(T).name()<<" "<< check<<" "<< objects_created<< endl;
sleep(1);
assert(0);
}
check=84;
//...
}
and it breaks when compiled with g++4.6
3 0x00007ffff65ec7a4 in counter<Node>::~counter (this=0x614c60,
__in_chrg=<value optimized out>)
at /home...
4 0x00007ffff65e7a4d in Node::~Node (this=0x614c60,
__in_chrg=<value optimized out>)
at /home...
5 0x00007ffff6603cf2 in std::_Destroy<Node> (__pointer=0x614c60)
at /usr/include/c++/4.6/bits/stl_construct.h:92
6 0x00007ffff6600004 in std::_Destroy_aux<false>::__destroy<Node*> (
__first=0x614c60, __last=0x614d40)
at /usr/include/c++/4.6/bits/stl_construct.h:102
7 0x00007ffff65fa003 in std::_Destroy<Node*> (__first=0x614c60,
__last=0x614d40) at /usr/include/c++/4.6/bits/stl_construct.h:125
8 0x00007ffff65f2a4f in std::_Destroy<Node*, Node> (__first=0x614c60,
__last=0x614d40) at /usr/include/c++/4.6/bits/stl_construct.h:151
9 0x00007ffff65ecfb2 in std::vector < Node, std::allocator < Node>
>::~vector (
this=0x7ffff68329f8, __in_chrg= < value optimized out>)
at /usr/include/c++/4.6/bits/stl_vector.h:348
checkis static, which means that it is shared by all instances of the class. Since you wantcheckto be a normal class member, you should remove thestatickeyword.