Boost's data-driven tests' join operator `+` corrupts first column

泄露秘密 提交于 2019-12-06 01:54:27

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/48102512/boosts-data-driven-tests-join-operator-corrupts-first-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!