|
Boost : |
Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2009-12-17 13:03:00
Bo Persson wrote:
> Mathias Gaunard wrote:
>> Dean Michael Berris wrote:
>>> I've recently been seeing this error more and more especially on
>>> GCC with -Wall: /home/dean/boost/boost/optional/optional.hpp:407:
>>> warning:
>>> dereferencing pointer �<anonymous>� does break strict-aliasing
>>> rules /home/dean/boost/boost/optional/optional.hpp:427: note:
>>> initialized from here and:
>>>
>>> /home/dean/boost/boost/function/function_base.hpp:321: warning:
>>> dereferencing type-punned pointer will break strict-aliasing rules
>>> /home/dean/boost/boost/function/function_base.hpp:325: warning:
>>> dereferencing type-punned pointer will break strict-aliasing rules
>>>
>>> This is on Linux and GCC 4.4.1.
>>>
>>> I'm not an expert in this regard but is there a way to either
>>> silence or avoid these warnings? Anything you want me to try from
>>> my end?
>> This was discussed in the past, and some people claimed the warning
>> was spurious.
>>
>> I am personally not convinced whether it is spurious or not,
>> however.
>
> Using a reinterpret_cast to convert from one pointer type to an
> unrelated type seems to conflict with the rules at the end of chapter
> 3 of the standard.
>
> "If a program attempts to access the stored value of an object through
> an lvalue of other than one of the following
> types the behavior is undefined: ..."
>
>
> The gcc 4.4 documentation recommends using a union, instead of a type
> punned pointer or reference.
It is not a trivial problem and not uncommon at the same time.
Perhaps it would be a good idea if Boost provides some
(more or less) portable guidelines on the subject of strict
aliasing issues. On Wiki?
The most complete reference I've found so far is this:
http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
Best regards,
-- Mateusz Loskot, http://mateusz.loskot.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk