
On Thu, Dec 17, 2009 at 9:51 AM, Bo Persson <bop@gmb.dk> 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.
Union is also undefined. You can't portably write one type of data somewhere and then read something else. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode