Boost logo

Boost :

Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2009-12-18 02:17:55

On Fri, Dec 18, 2009 at 9:16 AM, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:
> On Thu, Dec 17, 2009 at 12:19 PM, Dean Michael Berris
> <mikhailberis_at_[hidden]> wrote:
>> I don't understand why it's "completely useless" when in cases where
>> they are done wrong it can cause a runtime crash.
> Because the information the compiler gives you in this case is "you
> have used reinterpret_cast, your program *might* violate the C++
> standard" but it can't know if you're violating it or not. So what it
> really says is "warning, you're using reinterpret_cast" which is
> useless because you know that you are using reinterpret_cast.

Are we still talking about the strict aliasing rules? Because the
strict aliasing stuff doesn't happen only where reinterpret_cast is
done. In the case of Boost.Optional and GCC 4.4 (which apparently has
a bug specific to this case) it's saying accessing a certain area in
memory whose pointer is cast to be a pointer to a type which might not
be related to the original type of the data in that area in memory
*may* cause a runtime error.

This is one of the reasons why I really don't like pointers in C/C++
-- the fact that its type can be modified in a standard manner makes
it really really dangerous. But then that's a completely different
matter altogether. ;)

>>> To someone who doesn't know the
>>> semantics of reinterpret_cast, perhaps the warning has some value, but
>>> for the rest of us what it really says is "Warning! You have used
>>> reinterpret_cast!"
>> Sure, but isn't reinterpret_cast considered bad because of the fact
>> that there is no standard implementation of it?
> I'm not sure what you mean. There is a standard implementation of
> reinterpret_cast.

Really? I thought this was implementation-defined?

If you mean 'static_cast<foo*>(static_cast<void*>(bar_ptr))' I don't
think it's guaranteed that that's really how reinterpret_cast is
implemented by compilers.

Dean Michael Berris | | |

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