This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Placement new[] weirdness
- To: "Andrey Slepuhin" <pooh at msu dot ru>, "Mike Stump" <mrs at wrs dot com>
- Subject: RE: Placement new[] weirdness
- From: "Jody Hagins" <jody at atdesk dot com>
- Date: Thu, 15 Jul 1999 17:32:20 -0400
- Cc: <egcs at egcs dot cygnus dot com>
> On 15-Jul-99 Mike Stump wrote:
> >> Date: Thu, 15 Jul 1999 18:40:22 +0400 (MEDT)
> >> From: Andrey Slepuhin <pooh@msu.ru>
> >> To: egcs@egcs.cygnus.com
> >
> >> --new(2,f) T[5] results in a
> call of
> >> operator new[](sizeof(T)*5+y,2,f).
> >> This means that a call of placement new[] operator
> >> new(p) T[N];
> >> returns p+x, where x is some implementation-defined constant.
> >> This makes placement new[] operator totally useless.
> >
> > You have us confused with comp.std.c++. I disagree with your
> > assessment.
>
> Well, may be comp.std.c++ more appropriate place for discussion,
> But indeed we have two different problems:
>
> 1) Whether C++ standard is well-formed on this topic.
> 2) If clause 18.4.1.3 of standard is right, then egcs is wrong.
>
> Note that I have *concrete* compiler, and all I want is
> to have this compiler conforming to C++ standard. And I ask egcs
> people because I have problems with *concrete* implementation.
But you are missing the point. You are confusing operator new []
(std::size_t, Something) with operator new [] (std::size_t, void *).
Section 18.4.1.3 specifically says that these placement forms are not
replaceable. Furthermore, the compiler notices the difference between these
various forms of new, and simply returns the pointer for the pre-defined
placement new. However, when allocating an array, it is perfectly allowed
to pad the value with whatever value it desires. You will still end up with
the right amount of memory in that case. I guess what you are worried about
is that operator new[](std::size_t, void *) would possible return something
different from what you passed as the pointer, and this is not the case. It
will definitely return whatever you tell it to return. The compiler is
supposed to differentiate between the various versions of placement new
(i.e., the one defined as un-replaceable by the language, and the various
ones that may be overloaded).