Boost logo

Boost :

Subject: [boost] gcc-4.4.0 and boost::optional is giving (spurious?) strict-aliasing warnings
From: Brad Spencer (spencer_at_[hidden])
Date: 2009-05-05 18:17:00


Before I get to the details, let me start by saying that I suspect
that these warnings are probably spurious. But, before I go and start
asking the compiler folks if they are bugs, I'd like to check here
first.

If you take unmodified boost-1.38.0 and try to use boost::optional
with gcc-4.4.0 -Wall -O3, you seem to get warnings about
strict-aliasing rules being broken. If boost::optional (and
boost::function) are really broken, then we're probably in trouble :)

test.cc:

#include <boost/optional.hpp>
boost::optional<int> x;
int func()
{
  return *x;
}

On x86_64-unknown-linux-gnu:

$ /opt/gcc-4.4.0/bin/g++ -Wall -O3 -I. -c -o test.o test.cc
test.cc: In function ‘int func()’:
test.cc:5: warning: dereferencing pointer ‘<anonymous>’ does break strict-aliasing rules
./boost/optional/optional.hpp:594: note: initialized from here

I have seen some similar issues with boost::bind and boost::function,
but I haven't isolated them down to something this simple yet. I
figured I'd start by asking about this.

So, is it safe to presume that boost::optional is not really breaking
the strict aliasing rules? (It's not immediately obvious.) If so,
then I can ask the gcc folks about this.

Thanks!

-- 
----------------------------------------------------------
Brad Spencer - spencer_at_[hidden] - www.starscale.com



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