Le 04.01.18 à 15:13, Nate Widmyer via Boost-users a écrit :
Bonjour Raffi,
I was able to reproduce the crash with this minimal source:
#define BOOST_TEST_MODULE unit_test #include
struct f {
f() { boost::unit_test::master_test_suite_t master_test_suite = boost::unit_test::framework::master_test_suite(); /* crashes later because of this line */ } ~f() { } };
BOOST_FIXTURE_TEST_CASE(sample_test, f) { BOOST_TEST(true); }
I noted the critical line above.
My goal is to access the path of the executable, and that static getter to the master test suite is apparently the right way to get it.
You are not getting a ref but a copy of the master test suite. You should change the line to boost::unit_test::master_test_suite_t& boost::unit_test::framework::master_test_suite();
I've been able to bypass the crash by avoiding keeping the ref as a local variable:
f() { boost::filesystem::path exe_dir = boost::filesystem::system_complete(boost::unit_test::framework::master_test_suite().argv[0]) .remove_filename(); }
In this example, you are properly accessing the master_test_suite by reference.
IMHO it still seems like a bug that a ref returned in the fixture constructor causes a crash later on program termination?
There is a bug in the sense that we still allow for copying the master test suite. I will remove this possibility.
Hope this helps. Thanks again for your time,
Thank you! Raffi