destructor of static object not called
Gabriel Dos Reis
gdr@codesourcery.com
Tue Aug 22 02:09:00 GMT 2000
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.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
More information about the Gcc-bugs
mailing list