|
Boost : |
Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2009-12-18 15:24:41
On Fri, Dec 18, 2009 at 6:19 PM, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:
> On Fri, Dec 18, 2009 at 11:07 AM, Felipe Magno de Almeida
> <felipe.m.almeida_at_[hidden]> wrote:
[snip]
>> It is not portable if we dereference it, which optional does.
>
> I am going off of what Giovanni said earlier in this thread about how
> optional works, which seems to contradict your statement above.
I re-read what Giovanni said. And it seems to me it still dereferences it.
Indirectly, but does it.
If a perfectly valid implementation negates the bits in a a pointer
for a reintepret_cast and you pass it to placement new it will
probably fail.
[snip]
>>> Casting to a pointer of unrelated type doesn't suite static_cast,
>>> reinterpret_cast is a better choice.
>>
>> I don't understand why.
>> How is reinterpret_cast better than static_cast?
>
> In this case reinterpret_cast is a better choice because even with
> static_cast, the cast is just as unsafe, but may appear safer because
> static_cast is perceived as safer than reinterpret_cast.
It is not just as unsafe. static_cast is guaranteed to do what is
needed. reinterpret_cast doesn't. It is implementation-defined and can
do whatever it wants, as long as a reinterpret_cast back results in
the same pointer as before.
> You don't want to make it harder for the programmer to see that the
> operation is potentially dangerous, do you?
It is if you do reintepret_cast. Not if you do static_cast.
> Emil Dotchevski
> Reverge Studios, Inc.
> http://www.revergestudios.com/reblog/index.php?n=ReCode
[snip]
-- Felipe Magno de Almeida
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk