[test] Bug in macros when used with valarray?
I have a bug in my program that looks as though it might be in the macros in test. The following line gives me a segmentation fault: BOOST_CHECK_SMALL(var[a][b].first, accuracy); The variable "var" is of type boost::shared_array<std::pair<double, std::valarray<double> > >, for which memory has been allocated as follows (with variable names disguised): const unsigned int num_elements1 = /* some value */; const unsigned int num_elements2 = /* some other value */; const unsigned int num_elements3 = /* another value */; boost::shared_array<boost::shared_array<std::pair<double, std::valarray<double> > > > var_array( new boost::shared_array<std::pair<double, std::valarray<double>
[num_elements1]);
for (unsigned int a = 0; a != num_elements1; ++a) { var[a].reset(new std::pair<double, std::valarray<double>
[num_elements2]);
for (b = FirstSolution; b != num_elements2; ++b) { var[a][b].second.resize(num_elements3); } } The variable "accuracy" is of type double. The variable is then passed to a test case: test_suite -> add(BOOST_TEST_CASE(boost::bind(my_test, var))); with this header: void my_test(boost::shared_array<boost::shared_array<std::pair<double, std::valarray<double> > > >& var) Within this test, "var" is passed to another function (by reference) and its contents are set. Outputting the contents shows they have been set OK (using the same array indices, note), but the segmentation fault occurs when the BOOST_CHECK_SMALL macro is used. I am using version 1.33.1 of Boost for gcc 3.2.3. I am linking against -lboost_unit_test_framework-gcc-d-1_33_1 and -lm I'm sure I have used this before without any problems in Linux. The program works perfectly well in Windows using MSVC and Boost version 1.33.1. Are there any other link flags I should be using? Is there something else I have missed? Of course, it is entirely possible that I have an array-out-of-bounds error in my code or something like that, but my diagnostics aren't picking anything like this up, and the Windows version does not report any errors with security checks enabled, and, as I say, outputting the values to std::cout does not cause a segmentation fault. Is it possible that the BOOST_CHECK_* macros don't work with std::valarray in Boost 1.33.1 for gcc 3.2.3? Thanks.
"Paul Giaccone" <paulg@cinesite.co.uk> wrote in message news:461F7092.3020207@cinesite.co.uk...
I have a bug in my program that looks as though it might be in the macros in test.
The following line gives me a segmentation fault:
BOOST_CHECK_SMALL(var[a][b].first, accuracy);
The variable "var" is of type boost::shared_array<std::pair<double, std::valarray<double> > >, for which memory has been allocated as follows (with variable names disguised):
I might be missing somethig, but doesn't var[a] have a type std::pair<double,std::valarray<double> > so the expression var[a][b] doesn't make sence? ....
Outputting the contents shows they have been set OK (using the same array indices, note), but the segmentation fault occurs when the BOOST_CHECK_SMALL macro is used.
Did the UTF caught the segmentation failt? Did you try to use the debugger and see where does it crash? ...
Is it possible that the BOOST_CHECK_* macros don't work with std::valarray in Boost 1.33.1 for gcc 3.2.3?
BOOST_CHECK_SMALL( x, t ) translates into simple abs(x) < abs(t) I do not see how it could cause any segmentation faults. I might be some code generation bug (I've had several problems with this compiler). Otherwise you will have to dig in yourself with debugger. you could also provide simple example that illustrate the issue and I could try to reproduce it here. Gennadiy
participants (2)
-
Gennadiy Rozental
-
Paul Giaccone