This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Placement new[] weirdness


On 15-Jul-99 Jody Hagins wrote:
> 
>> 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.

I *don't* want to overload it. I want to use it.
So all my words are about operator new [] (std::size_t, void *).

>  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.

This is Ok. No worry.

>  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).

I'm worrying because according 5.3.4 placement operator new[] needs
implementation-defined amount of additional storage to save a size
of array. So if I want to create an array of e.g. 5 elements of class T
using placement new[], I need to have a peace of 5*sizeof(T)+<some_constant>
bytes, where <some_constant> is implementation defined and is unknown at
compile time. And this is how this works in egcs. E.g. on i386-linux
p=new(p) T[<size>]; increments p by 4, so I probably need 4 additional bytes.

But 18.4.1.3 says that placement new[] should return the same pointer
as was passed to it. Well, if this a typo in standard, no questions.
But I *can* imagine implementation of placement operator new[] which
will conform to this clause.

Regards,
Andrey.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]