Boost logo

Boost :

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


On Fri, Dec 18, 2009 at 3:10 AM, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:
> On Thu, Dec 17, 2009 at 10:07 AM, Giovanni Piero Deretta
> <gpderetta_at_[hidden]> wrote:
>> ... but the dynamic type of the internal buffer of boost::optional has
>> been changed via placement new, so (modulo compiler bugs) it should be
>> safe: at any time the buffer has a specific type (when initialized) or
>> no type at all (it is just a bunch of memory). Boost optional only
>> dereferences the buffer when it has been initialized, and always with
>> the same type used for placement new. Of course this is hard
>> (impossible?) to prove statically and gcc warns even if it should be
>> perfectly safe .
>
> We had a discussion about warnings some time ago, I think this is an
> excellent example of a warning that warns about something important
> yet it is completely useless.

I don't understand why it's "completely useless" when in cases where
they are done wrong it can cause a runtime crash.

> 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 don't see why the
warning doesn't help you know that there is something *potentially*
wrong with the implementation.

I still have not seen any other concrete ways of avoiding (or
silencing) this warning at the code level. Maybe some pragmas to
disable the warning if we're all really convinced this is a spurious
warning?

-- 
Dean Michael Berris
blog.cplusplus-soup.com | twitter.com/mikhailberis
linkedin.com/in/mikhailberis | facebook.com/dean.berris | deanberris.com

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