id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 12001,"Under C++11, BOOST_TEST() wrong on boost::optional + named-parameter-idiom example",Tony Lewis ,Gennadiy Rozental,"The example below shows the `BOOST_TEST()` assertions failing where they should pass, as the equivalent `BOOST_CHECK_EQUAL()` assertions do. It looks as though `BOOST_TEST()` is preventing the named-parameter-idiom setter from changing the `optional` value from `boost::none`. Importantly, this code works if compiled without `-std=c++11`. Compile commands: {{{ g++ -std=c++11 -isystem $BOOST_ROOT/include test_test_bug.cpp -L$BOOST_ROOT/lib -lboost_unit_test_framework-mt setenv LD_LIBRARY_PATH $BOOST_ROOT/lib ./a.out -l all }}} Code: {{{ #!cpp #ifndef BOOST_TEST_DYN_LINK #define BOOST_TEST_DYN_LINK #endif #include #include #include #include class my_class { private: boost::optional num; public: my_class(const boost::optional &arg_num) : num ( arg_num ) {} const boost::optional & get_num() const { return num; } const my_class & set_num(const boost::optional &arg_num) { num = arg_num; return *this; } }; // Simple stream insertion operator std::ostream & operator<<(std::ostream &os, const my_class &my_obj) { os << ""my_class[ "" << my_obj.get_num() << "" ]""; return os; } // Simple equality predicate operator bool operator==(const my_class &my_obj_a, const my_class &my_obj_b) { return ( my_obj_a.get_num() == my_obj_b.get_num() ); } BOOST_AUTO_TEST_CASE(my_test) { const my_class correct_answer( 5 ); // These two work as expected BOOST_CHECK_EQUAL( my_class( boost::none ).set_num( 5 ), correct_answer ); BOOST_CHECK_EQUAL( correct_answer, my_class( boost::none ).set_num( 5 ) ); // These two fail, evaluating the non-trivial side as ""my_class[ -- ]"" BOOST_TEST ( my_class( boost::none ).set_num( 5 ) == correct_answer ); BOOST_TEST ( correct_answer == my_class( boost::none ).set_num( 5 ) ); } bool init_function() { return true; } int main( int argc, char* argv[] ) { return ::boost::unit_test::unit_test_main( &init_function, argc, argv ); } }}}",Bugs,closed,To Be Determined,test,Boost 1.60.0,Problem,obsolete,"test,optional,BOOST_TEST,BOOST_CHECK_EQUAL,c++11,named parameter idiom",