Is explicit template qualification required for explicit delete?



 DEVELOP > c-Plus-Plus > Is explicit template qualification required for explicit delete?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "J.T. Conklin"
Date: 10 Aug 2004 12:50:48 PM
Object: Is explicit template qualification required for explicit delete?
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
--
J.T. Conklin
.

User: "David Hilsee"

Title: Re: Is explicit template qualification required for explicit delete? 10 Aug 2004 09:06:39 PM
"J.T. Conklin" <jtc@acorntoolworks.com> wrote in message
news:874qnaubk7.fsf@orac.acorntoolworks.com...

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.

Well, my copy of the standard says that a destructor call is ~class-name,
and a template-id (template name with arguments, e.g. Handle<int>) qualifies
as a class-name, so the universal acceptance of ~Body<T>() makes sense to
me. The other option for class-name is identifier, which doesn't help me
much. It is true that Handle is an identifier, but that doesn't necessarily
mean that it can be used to invoke the destructor, right? I'm probably
missing something. You might want to also post this to
comp.lang.c++.moderated, if you haven't already.
--
David Hilsee
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER