 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
apm Guest
|
Posted: Sat Sep 25, 2004 5:42 am Post subject: What is the standard signature for an allocator destructor? |
|
|
My reading of the std is that the signature of a custom allocator
should follow the pattern laid out by the default allocator.
Section 20.1.5 (page 354) says that the std library lays down the
requirements for allocators. The requirements are in table 32 (page
356). However, the table does not specify signatures for the allocator
constructor or destructor. It is reasonable to assume (IMO) that the
signatures should follow the form of the default allocator in section
20.4.1. I cannot find anywhere in the std where it actually says this
though.
This causes a serious problem: if one inherits from a custom allocator
that DOES conform to the default allocator dtor signature then the
derived class must also have a dtor with an empty throw list.
Otherwise a compilation error can result (not all compilers watch out
for this but some definitely do). This issue just caused a compilation
error in some code I am working on. So it is a real problem.
Suppose the derived class had been written by someone else. And that
it could not be changed. Then I would have to change the signature of
my allocator dtor so as NOT to conform to the pattern laid out in
section 20.4.1 to make the compilation error go away. But I feel that
this change makes me violate the std. Except that the std seems to be
a little grey in this area. Can anyone shed any light please? I would
like to tell the author of the derived class that he has to change
because I am conformant and he is not. But its hard to do that when
the std doesnt seem to cover it completely.
Regards,
Andrew Marlow
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Frank Birbacher Guest
|
Posted: Mon Sep 27, 2004 10:31 am Post subject: Re: What is the standard signature for an allocator destruct |
|
|
Hi!
apm wrote:
| Quote: | However, the table does not specify signatures for the allocator
constructor or destructor. It is reasonable to assume (IMO) that the
signatures should follow the form of the default allocator in section
20.4.1. I cannot find anywhere in the std where it actually says this
though.
|
For the copy constructor, yes. And for the 'rebinding copy ctor',
which contructs a new allocator for a different type.
The default ctor however is not required, as e.g. std containers
like vector take an instance of an allocator as the last
parameter in their ctors.
| Quote: | This causes a serious problem: if one inherits from a custom allocator
that DOES conform to the default allocator dtor signature then the
derived class must also have a dtor with an empty throw list.
Otherwise a compilation error can result (not all compilers watch out
for this but some definitely do). This issue just caused a compilation
error in some code I am working on. So it is a real problem.
|
Just because a base class has a non-throwing dtor, doesn't mean
the derived class has a non-throwing dtor, unless the dtor is
virtual. I think dtors of allocators must not be virtual because
the std container store a copy of the given allocator and there
object slicing must be avoided. Thus you need to specify the
exact type of the allocator in use, and thus you don't need a
virtual dtor. But I don't know whether the allocator dtor must be
non-throwing.
Frank
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
apm Guest
|
Posted: Fri Oct 01, 2004 4:39 pm Post subject: Re: What is the standard signature for an allocator destruct |
|
|
Frank Birbacher <bloodymir.crap (AT) gmx (DOT) net> wrote
| Quote: | Hi!
apm wrote:
However, the table does not specify signatures for the allocator
constructor or destructor. It is reasonable to assume (IMO) that the
signatures should follow the form of the default allocator in section
20.4.1. I cannot find anywhere in the std where it actually says this
though.
For the copy constructor, yes.
|
Well that's what I think also, but where does it say so in the std?
| Quote: | This causes a serious problem: if one inherits from a custom allocator
that DOES conform to the default allocator dtor signature then the
derived class must also have a dtor with an empty throw list.
Otherwise a compilation error can result (not all compilers watch out
for this but some definitely do). This issue just caused a compilation
error in some code I am working on. So it is a real problem.
Just because a base class has a non-throwing dtor, doesn't mean
the derived class has a non-throwing dtor, unless the dtor is
virtual.
|
So when I got the compilation error, that was a compiler bug?
| Quote: | But I don't know whether the allocator dtor must be
non-throwing.
|
I welcome more input concerning where this is covered in the std, please.
-apm
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|