This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

explicit destructor calls w/templates


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]