site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Hello, I would like to submit a problem we recently discovered, when using : The problem does not occur when : * using Apple gcc 3.3, both with or without optimization * not using optimization (-O0) Below is the sample program : ---- file boost_unit_test_gcc4_pb_sample.cpp --- #include <iostream> #include <boost/test/unit_test.hpp> using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; using namespace std; class SampleTest { public: SampleTest (int val) : a (val) { } int a; void sampleTest () { std::cout << "a : " << a << std::endl; BOOST_CHECK_EQUAL (a, 12345); } }; When compiled when the above command, and running the program : export DYLD_LIBRARY_PATH=${BOOST_PATH}/lib ./boost_unit_test_gcc4_pb_sample *** 1 failure detected in test suite "Sample test" --- When compiled without optimization (-O0), and running, the result is : ---- Running 1 test case...a : 12345 *** No errors detected ---- Any help would be greatly appreciated ! Regards, Anand _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... * gcc 4.0.1 : Apple version coming with XCode 2.2.1 (build 5250) or gcc 4.0.2 delivered by darwinports. * boost library, tried with 1.33.1, 1.33.0 * using optimization level, either -O, -O1 or -O2 test_suite* init_unit_test_suite( int argc, char* argv[] ) { test_suite* test= BOOST_TEST_SUITE( "Sample test" ); boost::shared_ptr<SampleTest> instance (new SampleTest (12345)); test->add (BOOST_CLASS_TEST_CASE ( & SampleTest::sampleTest, instance)); return test; } ---- end-of-file boost_unit_test_gcc4_pb_sample.cpp --- And the command used for compiling : BOOST_PATH=<path-to-your-boost-install> /usr/bin/g++-4.0 -O2 -I${BOOST_PATH}/include -L${BOOST_PATH}/lib - lboost_unit_test_framework boost_unit_test_gcc4_pb_sample.cpp -o boost_unit_test_gcc4_pb_sample The result is the following : ---- Running 1 test case...a : 13691 boost_unit_test_gcc4_pb_sample.cpp(18): error in " SampleTest::sampleTest": check a == 12345 failed [13691 != 12345] It seems that when sampleTest () method is called by unit_test framework, adress of "a" variable is wrong, leading to a test failure. When, instead of using a class or struct attribute for variable "a", either a global, or class static variable is used, the problem disappears. Has anyone some experience using Boost unit_test framework on Mac OS X, using gcc 4 ? This email sent to site_archiver@lists.apple.com