Boost logo

Boost :

Subject: Re: [boost] gcc-4.4.0 and boost::optional is giving (spurious?) strict-aliasing warnings
From: Thomas Sondergaard (ts_at_[hidden])
Date: 2009-07-15 17:43:08


On 2009-05-15 21:11, Fernando Cacciola wrote:
> Hi All,
>
> Sorry but I just couldn't find time to answer this before.
>
>> On Thu, May 7, 2009 at 3:37 AM, Kim Barrett
>> <kab.conundrums_at_[hidden]> wrote:
>>> At 7:17 PM -0300 5/5/09, Brad Spencer wrote:
>>> In boost/aligned_storage.hpp, the class template
>>> boost::aligned_storage defines its address member function thusly:
>>>
>>> void* address() { return this; }
>>> const void* address() const { return this; }
>>>
>>
>> I'm not 100% sure, but this could be very wrong as, IIRC, there is no
>> guarantee that for non PODS the address of the first element (i.e.
>> aligned_storage.data_) is the same as 'this'.
>>
>> but why doesn't aligned storage implements address() as:
>>
>> void * address { return this.data_.data_.buf; }
>>
>> BTW, I see that boost optional actually uses its own implementation of
>> aligned storage,
>
> Indeed.. whose code is not like the one above.
>
>> whose address member function returns a pointer to a
>> char buffer, so it shouldn't be a problem.
>>
> Precisely... a char* is explcitely allowed to alias any object, so, for
> Boost.Optional at least, the warning is clearly spurious.
>

Has this issue been reported to gcc, then? I searched their bugzilla and
didn't find anything relevant.

I'm also curious whether someone has found a workaround for this. I'd
like to patch optional.hpp, so I can keep building with -Werror.

Regards,

Thomas Sondergaard


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