6

Consider the following code:

BOOST_DATA_TEST_CASE(
      sampleTest,
      (data::make(1) ^ data::make(2)) + (data::make(3) ^ data::make(4)),
      var1,
      var2)
{
  std::cout << var1 << "," << var2 << std::endl;
}

The output I expect is:

1,2
3,4

However, var1 appears to be corrupt:

$> ./MyTests --run_test=Tests/sampleTest
Running 2 test cases...
202875304,2
202875304,4

*** No errors detected
$> ./MyTests --run_test=Tests/sampleTest
Running 2 test cases...
83976616,2
83976616,4

*** No errors detected

Am I doing something wrong?

3
  • I get a warning (treated as an error, since I use -Werror) on the dataset line: error: returning reference to temporary [-Werror=return-local-addr]. Are you using a high warning level, and do you get any such warning? Jan 4, 2018 at 20:15
  • @FredLarson I never got a warning but if I turn it into an error I do indeed see it: join.hpp:57:58: error: returning reference to local temporary object [-Werror,-Wreturn-stack-address]
    – Addy
    Jan 4, 2018 at 20:48
  • Yeah, something about this is producing undefined behavior. I think it has something to do with joining the results of zips, but I haven't tried data-driven tests before. Jan 4, 2018 at 20:53

1 Answer 1

2

That's a bug. Long story short: please report it to the library maintainers.

Indeed, the zip operation returns a tuple std::tuple<int const&, int const&>:

and though the dataset itself is properly alive at the time, the tuple is returned by reference in the join operation...:

    sample const&       operator*() const   { return m_first_size > 0 ? *m_it1 : *m_it2; }

The proper fix would be to extend the dataset concept to not only have a ::sample type¹ but also a ::reference type. That's quite an invasive change.


¹ strangely not documented at this time

1
  • 1
    You should probably have included a link so they don't have to do double work.
    – sehe
    Jan 6, 2018 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.