RE: ctor unnecessarily wiping of PODs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the quick response.
> The C++ standard says that for a POD type the initializer () will cause it to be zero-initialized.
No the standard says: If I don't init the POD with an initializer or otherwise, I have to expect dirty memory there.

n and u are being inited even with the default constructor.  With ctor uncommented I would expect n() to init just n and the array to be uninitialized.

> If that's not what you want, use:
>      new (v) Ray2;
> void makeRay(void*v){
>	new(v)Ray2;
> }
Does the same thing.  Semantics are identical.

Chris


-----Original Message-----
From: Jonathan Wakely [mailto:jwakely.gcc@xxxxxxxxx] 
Sent: Monday, March 19, 2012 7:19 PM
To: Hite, Christopher
Cc: gcc-help@xxxxxxxxxxx
Subject: Re: ctor unnecessarily wiping of PODs

On 19 March 2012 17:12, Hite, Christopher wrote:
> Hi,
>
> I think I've got an optimizer bug producing a bzero of data that doesn't need initialization.
>
> Whether Ray has a ctor defined or not gcc wipes the memory 257 words for no reason.  What does have an effect is if you call the ctor of just  Ray it doesn't clear the data.
>
> One would expect none of the PODs to be inited unless explicitly done 
> so in the code
>
> I'm guessing there's some kind of a bzero optimization where padding and non-inited PODs can be cleared along with several fields that need to be.  I'm guessing that this optimization is broken somehow.
>
> I'm getting this on gcc 4.6.0 debug and O3.
>
> struct Ray{
>        unsigned n;g
>        int u[0x100];
>        //Ray() : n() {}
> };
>
> struct Ray2: Ray {};
>
> void makeRay(void*v){
>        new(v)Ray2();

The C++ standard says that for a POD type the initializer () will cause it to be zero-initialized.

If that's not what you want, use:
     new (v) Ray2;



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux