Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2010-09-22 16:28:34


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 22 September 2010, Larry Evans wrote:
> On 09/22/10 14:04, Frank Mori Hess wrote:

> > I don't see how that gets around the anti-aliasing rules. The compiler
> > is allowed to assume incompatible pointers won't _ever_ alias. So just
> > because your program does things in a certain order doesn't mean the
> > compiler isn't allowed to use the anti-aliasing assumptions to reorder
> > things in a nasty way. Couldn't it look at the destruction of the old
> > object and the construction of the new object as two completely
> > independent actions it is free to reorder or interleave?
>
> I hadn't thought of the compiler reordering the calls.
> Just to be clear, the compiler, using the anti-aliasing rules,
> could reorder:
>
> 316 destroy();
> 317 assign_copy(from);
>
> to:
>
> 317 assign_copy(from);
> 316 destroy();
>
> ? Or maybe just do everything in destroy before the lhs->~Lhs() call,
> then execute assign_copy(from) and then do lhs->~Lhs(). Hmm...
> OK, I think I got it, but am surprised.

I think so, in principle. I only have a vague idea of what optimizing
compilers actually do under the hood though, which is why I tend to be very
conservative about obeying the strict aliasing rules (they've bitten me
before).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkyaZvIACgkQ5vihyNWuA4W0ZACg2fcasot2btTi72ddKDI8BaZI
svoAnRpUsfH2XPOs5bAFj9DaEYsJEGPU
=RdVG
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk