473,513 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 22 '05 #1
1 1571
"J.T. Conklin" <jt*@acorntoolworks.com> wrote in message
news:87************@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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1710
by: Aman | last post by:
Hi, I'm using the g++ compiler to compile this on SunOS 5.8. I get compilation errors when I use A* as return type but none when I used void . why is this ? regards, Aman. ----------errors...
4
1825
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
4
1505
by: an0 | last post by:
Bjarne Stroustrup's "The C++ Language Programming" says at P330: "Within the scope of String<C>, qualification with <C> is redundant for the name of the template itself, so String<C>::String is the...
15
1442
by: silverburgh.meryl | last post by:
Hi, I am trying to write a transform_until template. It is bascially doing what transform is doing except if UnaryOperation return NULL, it will break out from the loop. Here is the code, but...
1
3058
by: krunalbauskar | last post by:
Hi, Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. For example - <snippet> #include <iostream> #include <vector>
10
3152
by: jlongstreet | last post by:
Please correct any misconceptions, or voice concerns about this being a stupid idea in general. I was wondering today: why doesn't C++ have explicit typedefs? explicit typedef unsigned int...
2
7676
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
3
2839
by: Pierre Yves | last post by:
Hi there, Template, once again... Nice topic but a bit tricky to code. My problem is the following: I have to video parser which retrieve image frames. The pixel values can be unsigned char...
4
1442
by: Jimmy | last post by:
Hi, The other day, my boss corrected me to use "explicit qualification" instead of using "using directive". she asked me to use : "System.Data.DataSet ds = new System.Data.DataSet();" ...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.