Boost logo

Boost :

Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2009-12-18 09:55:23

On Fri, Dec 18, 2009 at 12:21 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
> Felipe Magno de Almeida wrote:


>> 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.
> Maybe, in principle, but if you try to write such a compiler you'll find
> that it isn't as easy, even if we dismiss C compatibility as a concern and
> stick to C++03. (In the latest C++0x draft reinterpret_cast for pointers to
> standard layout types is defined to do the static_cast dance.)

Would be really strange to write such compiler. But we don't have any
reason to use reinterpret_cast. The only reason I can think of is
typing less, and that's not a very compelling argument.

>> IMO we should be using static_cast<T2*>(static_cast<void*>(x)) which
>> is not implementation-defined.
> There isn't much difference. In practice, the two do the same thing. g++
> should issue the same warning for both; it doesn't because the current
> frontend isn't smart enough to see through the intermediate void*.

There is IMO. I know it is not related to the warning problem in gcc though.
But one uses implementation-defined behavior, the other doesn't.
I don't see any reason why we should prefer the implementation-defined behavior.

Felipe Magno de Almeida

Boost list run by bdawes at, gregod at, cpdaniel at, john at