A simple Boost Data Test doesn't compile if an argument is named t

83 views Asked by At

In the Boost.Test documentation, the following example is given

#define BOOST_TEST_MODULE dataset_example62
#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

namespace data = boost::unit_test::data;

int samples1[] = {1, 2};
int samples2[] = {8, 9, 10};

BOOST_DATA_TEST_CASE(
  test1,
  data::make(samples1) + samples2,
  var)
{
  std::cout << var << std::endl;
}

and this compiles fine from the (Win10) command line with g++. Based on this example, I wrote my own test case, but instead of var, I've used t, and compilation failed. To my surprise, even in the example above, when var is replaced by t in both places like so:

BOOST_DATA_TEST_CASE(
  test1,
  data::make(samples1) + samples2,
  t)
{
  std::cout << t << std::endl;
}

470 lines of errors appear after compiling. If I replace t with u, everything is ok again. Am I missing something crucial here, or is this a bug?

1

There are 1 answers

0
sehe On BEST ANSWER

Yeah. That's an interesting collision. I wouldn't call it a bug, but it is certainly a QoI-snag.

It's a direct consequence of unhygienic macros which isn't properly defended against by using "reserved" identifier conventions.

The macro expands to some 70 lines of code, and in all of that is buried

test1case t;

This causes the problem.

The library devs certainly gave thought to clash-preventing naming, seeing that the rest of the macro includes locals with names like context_frame_140, test1_registrar140 and test1case_registrar141 etc/

The library devs will probably appreciate if you make them aware of this oversight at https://github.com/boostorg/test/issues