Subject: Re: [boost] [test] BOOST_TEST macro and std::max
From: Benedek Thaler (thalerbenedek_at_[hidden])
Date: 2016-01-09 05:32:14


On Thu, Jan 7, 2016 at 12:33 AM, Gennadiy Rozental <rogeeff_at_[hidden]>
wrote:

> report_assertion(
> E.evaluate(),
> BOOST_TEST_LAZY_MSG( "description" ),
> __FILE__,
> __LINE__,
> ::boost::test_tools::tt_detail::CHECK,
> ::boost::test_tools::tt_detail::CHECK_BUILT_ASSERTION,
> 0 );
>
> You can unwrap remaining macros as well. Can you try to create trivial
> example illustrating the issue? you can replace report_assertion with your
> own function and get rid of the most of Boost.Test references (including
> BOOST_AUTO_TEST_CASE).
>
>
I reduced the original example to this: (plus includes)

bool my_report_assertion(
  boost::test_tools::assertion_result const& ar,
  boost::test_tools::tt_detail::lazy_ostream const& assertion_descr
) {
  if (!ar) {
    std::cout << "Failed: " << assertion_descr << " -- " << ar << std::endl;
  }

  return true;
}

int main()
{
  auto const& E = ::boost::test_tools::assertion::seed()->*3u ==
((std::max)(0u, 3u));
  my_report_assertion(
    E.evaluate(),
    (::boost::unit_test::lazy_ostream::instance() <<
::boost::unit_test::const_string( " ", sizeof( " ") - 1))
  );
}

It prints "Failed: -- 0", with and without -O2. Removing the lazy_ostream
or the << call, or the std::max expression fixes the issue (prints nothing).

My gcc version is:
g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204

The preprocessed file is 138k lines long, I'm not sure how to proceed.

Benedek