Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2009-12-18 08:46:08
On Fri, Dec 18, 2009 at 6:11 AM, Emil Dotchevski
> On Thu, Dec 17, 2009 at 11:17 PM, Dean Michael Berris
> <mikhailberis_at_[hidden]> wrote:
>> Really? I thought this was implementation-defined?
> Sure, but it is specified that if you reinterpret_cast from T1* to
> T2*, then reinterpret_cast the resulting T2* back to T1*, you'll get
> the original value (as long as T2 doesn't have stricter alignment
But nothing else is guaranteed. The compiler might very well increment
it by one byte when casting to T2 and then decrement it when casting
it back. It is perfectly valid behavior for reinterpret_cast.
IMO we should be using static_cast<T2*>(static_cast<void*>(x)) which
is not implementation-defined.
> Reinterpret_cast is tricky but it is part of the language and it's
> lame for the compiler to warn when it is used.
> Emil Dotchevski
> Reverge Studios, Inc.
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Felipe Magno de Almeida