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

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 :)

#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 In function ‘int func()’: 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.


Brad Spencer - spencer_at_[hidden] -

Boost list run by bdawes at, gregod at, cpdaniel at, john at