Boost logo

Boost :

Subject: Re: [boost] [move] GCC bug and aliasing questions
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2012-06-21 15:46:09


El 20/06/2012 19:54, Tr3wory escribió:
> But rv<TYPE> is derived from TYPE so to me it looks like the two type
> is compatible, therefore the code didn't violate the strict aliasing
> rules, so the attribute is not necessary.
> (BTW can we violate the strict aliasing rules trough static_cast if we
> don't do any chained conversion trough void*?)

It might not break strict aliasing (I'm not an expert) but it is
undefined behavior to static_cast down a hierarchy to a type that isn't
actually the type of the object. Boost.Move uses this undefined behavior
hole and the GCC behavior is fixed with may_alias. I haven't found a
better solution.

> On the other hand, if it's really breaks the rules then we solved the
> problem for gcc, but we still have undefined behavior on every other
> compiler.

It's undefined behavior in GCC also.

> Can we fix this somehow?

I haven't found a better alternative.

Ion


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