Boost logo

Boost :

Subject: [boost] [signals2] Test failure in C++11 (trivial fix for incorrect usage of boost::optional)
From: Ben Pope (benpope81_at_[hidden])
Date: 2013-12-11 02:26:52


I have the following errors:
"clang++-3.4" -c -x c++ -std=c++11 -stdlib=libc++ -O0 -g -fno-inline
-Wall -g -DBOOST_ALL_NO_LIB=1 -DBOOST_TEST_NO_AUTO_LINK=1 -I".." -o
"/home/ben/development/boost/test/build/results/boost/bin.v2/libs/signals2/test/signal_test.test/clang-linux-3.4~c11_libc++/debug/link-static/signal_test.o"
"../libs/signals2/test/signal_test.cpp"

../libs/signals2/test/signal_test.cpp:32:16: error: invalid operands to
binary expression ('boost::optional<int>' and 'int')
        if(max == false) max = *first;
           ~~~ ^ ~~~~~

"clang++-3.4" -c -x c++ -std=c++11 -stdlib=libc++ -O0 -g -fno-inline
-Wall -g -DBOOST_ALL_NO_LIB=1 -DBOOST_TEST_NO_AUTO_LINK=1 -I".." -o
"/home/ben/development/boost/test/build/results/boost/bin.v2/libs/signals2/test/track_test.test/clang-linux-3.4~c11_libc++/debug/link-static/track_test.o"
"../libs/signals2/test/track_test.cpp"

../libs/signals2/test/track_test.cpp:36:14: error: invalid operands to
binary expression ('boost::optional<int>' and 'int')
      if(max == false)

Richard smith explains the problem here:
http://llvm.org/bugs/show_bug.cgi?id=18180#4

"OK, I see what's happening -- in Clang 3.3 and GCC 4.8, 'false' is
being treated as a null pointer constant. boost::optional implicitly
converts to an "unspecified-bool-type" that happens to be a
pointer-to-member type, and thus can be compared against a null pointer
constant via the built-in operator!=(pointer-to-member,
pointer-to-member) overload.

In C++11 onwards, 'false' isn't a null pointer constant any more, so
this comparison is no longer valid. Clang 3.3 and GCC 4.8 don't
implement that rule; Clang 3.4 does."

The trivial fix is to change the if statements at:
../libs/signals2/test/signal_test.cpp:32:16:
../libs/signals2/test/track_test.cpp:36:14:

to if(!max) rather than if(max == false).

Ben


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