This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
explicit destructor calls w/templates
- From: jtc at acorntoolworks dot com (J.T. Conklin)
- To: gcc at gcc dot gnu dot org
- Date: Fri, 02 Jul 2004 19:27:52 -0700
- Subject: explicit destructor calls w/templates
- Reply-to: jtc at acorntoolworks dot com
I ran into some code that uses an explicit destructor calls for a
templated class. In earlier gcc versions the destructor call didn't
require a template argument, in 3.4 it does. Is this a result of the
new parser stricter behavior? I think it is, but even after googling,
grepping, and C++PLv3 reading I'm not 100% sure --- as I wasn't able
to find anything that described any interaction between explicit dtor
calls and templates.
This contrived example attempts to demonstrate the scenerio. It fails
to compile unless WITH_TEMPLATE_ARG is defined.
--jtc
template <class T>
class Base
{
public:
Base () { }
~Base () { cout << __PRETTY_FUNCTION__ << endl; }
};
template <class T>
class Derived
{
public:
Derived ()
{
x_ = new Base<T> ();
}
~Derived ()
{
#ifdef WITH_TEMPLATE_ARG
x_->~Base <T> ();
#else
x_->~Base ();
#endif
}
private:
Base<T> *x_;
};
int
main()
{
Derived<int> *x = new Derived<int> ();
delete x;
return 0;
}
--
J.T. Conklin