J
J.T. Conklin
I've been working on the configuration infrastructure for the ACE
framework which contains code that uses a templatized handle/body
idiom with placement new/delete. With g++ 3.4, we found that the
delete needed the addition of a template argument that wasn't needed
in earlier versions. I've checked this with Comeau C++ Online in
strict mode, and with Gimpel's Flexelint and neither reported any
issues with the code without the template argument. I realize that
whether a given compiler accepts/rejects a bit of code doesn't mean
anything, so I've checked C++PLv3 and the C++ standard, but haven't
been able to tell whether g++ is being strict, or is in error.
Here is some sample code that demonstrates the issue:
#include <cstdlib>
#include <new>
template <class T>
class Body
{
public:
Body () { }
~Body () { }
};
template <class T>
class Handle
{
public:
Handle ()
{
void *ptr = std::malloc(sizeof(Body<T>));
x_ = new (ptr) Body<T> ();
}
virtual ~Handle ()
{
#ifdef WITH_TEMPLATE_ARG
x_->~Body <T> ();
#else
x_->~Body ();
#endif
std::free(x_);
}
private:
Body<T> *x_;
};
int
main()
{
Handle<int> *x = new Handle<int> ();
delete x;
return 0;
}
Everything I've tried compiles this code with WITH_TEMPLATE_ARG defined,
but so far only g++ 3.4 rejects it without.
Many thanks,
--jtc
framework which contains code that uses a templatized handle/body
idiom with placement new/delete. With g++ 3.4, we found that the
delete needed the addition of a template argument that wasn't needed
in earlier versions. I've checked this with Comeau C++ Online in
strict mode, and with Gimpel's Flexelint and neither reported any
issues with the code without the template argument. I realize that
whether a given compiler accepts/rejects a bit of code doesn't mean
anything, so I've checked C++PLv3 and the C++ standard, but haven't
been able to tell whether g++ is being strict, or is in error.
Here is some sample code that demonstrates the issue:
#include <cstdlib>
#include <new>
template <class T>
class Body
{
public:
Body () { }
~Body () { }
};
template <class T>
class Handle
{
public:
Handle ()
{
void *ptr = std::malloc(sizeof(Body<T>));
x_ = new (ptr) Body<T> ();
}
virtual ~Handle ()
{
#ifdef WITH_TEMPLATE_ARG
x_->~Body <T> ();
#else
x_->~Body ();
#endif
std::free(x_);
}
private:
Body<T> *x_;
};
int
main()
{
Handle<int> *x = new Handle<int> ();
delete x;
return 0;
}
Everything I've tried compiles this code with WITH_TEMPLATE_ARG defined,
but so far only g++ 3.4 rejects it without.
Many thanks,
--jtc