Conversion Warning with GCC15 when using operator<< within custom failure message and -WConversion

Open
#448 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
testing-qa

Research direction

Start by reproducing the BOOST_TEST examples from the linked Boost.Test custom-messages documentation with GCC15 and -Wconversion, using the Compiler Explorer example as a reference. Trace the assertion and streamed-message conversion path; done means the examples retain their behavior without emitting the reported conversion warnings.

Written by the indexing model from the issue text.

Description

Starting with GCC15 ( when using -WConversion ) I get conversion warnings when using stream operator in custom failure messages.

Example code from the docs also produces those warnings:

Boost Test

#define BOOST_TEST_MODULE boost_test_message
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE( test_message )
{
  const int a(1), b(2);
  BOOST_TEST(a == b, "a should be equal to b: " << a << "!=" << b);
  BOOST_TEST(a != 10, "value of a=" << a);
}

Compiler Explorer Example

Warning:

<source>: In member function 'void test_message::test_method()':
<source>:8:62: warning: choosing 'boost::test_tools::tt_detail::assertion_evaluate_t<E>::operator boost::test_tools::assertion_result() [with E = boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<const int&>, const int&, boost::test_tools::assertion::op::EQ<int, int, void> >]' over 'boost::test_tools::assertion_result::assertion_result(const BoolConvertable&) [with BoolConvertable = boost::test_tools::tt_detail::assertion_evaluate_t<boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<const int&>, const int&, boost::test_tools::assertion::op::EQ<int, int, void> > >]' [-Wconversion]
    8 |   BOOST_TEST(a == b, "a should be equal to b: " << a << "!=" << b);
      |                                                              ^
<source>:8:62: warning:   for conversion from 'boost::test_tools::tt_detail::assertion_evaluate_t<boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<const int&>, const int&, boost::test_tools::assertion::op::EQ<int, int, void> > >' to 'boost::test_tools::assertion_result' [-Wconversion]
<source>:8:62: note:   because conversion sequence for the argument is better
Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/test

All issues in boostorg/test

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.