This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: destructor of static object not called
Gabriel Dos Reis wrote:
>
> Thomas Kunert <kunert@physik.tu-dresden.de> writes:
>
> | Hi,
> |
> | The code
> |
> | #include <iostream>
> | struct A {
> | void f(){};
> | A(){ std::cout << 1 << endl; }
> | ~A(){ for(;;); std::cout << 2 << endl;}
> | };
> | template<class T>
> | struct B {
> | B(){ a.f(); }
> | static A a;
> | };
> | template <class T>
> | A B<T>::a;
> | int main()
> | {
> | B<int> b;
> | }
> |
> |
> |
> |
> | gives the output
> |
> | 1
> |
> | but should give
> |
> | 1
> | 2
>
> Really?
>
> 14.7.1/1
>
> [...] The implicit instantiation of a class template specialization
> causes the implicit instantiation of the declarations, but *not* of
> the definitions or default arguments, of the class member functions,
> member classes, static data members and member templates [...]
>
> Emphasis is mine.
>
> Actually the bug is the construction of B<int>::a.
Thanks for your explanation.
I think, since the code actally refers to this static data member (in
the constructor of B) it should be initialized, as stated later in the
cited paragraph.
Regards,
Thomas