Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Problem using BOOST_TEST(a==b) to compare boost::variant in gcc12 in C++20 mode

Open
#484 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
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
testing-qa

Research direction

Start with the minimal reproduction using BOOST_TEST from boost/test/included_unit_test.hpp and inspect the comparison handling involved with boost/variant/variant.hpp under GCC 12 and C++20. Compare the parenthesized workaround with the failing form; done means variant comparisons compile without losing BOOST_TEST's smart decomposition, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Description

I'm using Boost 1.90, and comparing two variants within a BOOST_TEST macro fails.

I believe the C++20 comparison rewiriting rules is creating problems with this compiler.

This is the minimal repro I distilled in godobolt: https://godbolt.org/z/8q1ja37G6

#include <boost/variant.hpp>
#include <boost/test/included/unit_test.hpp>
#include <iosfwd>

struct A {};
struct B {};

bool operator== (const A& lhs, const A& rhs);
bool operator== (const B& lhs, const B& rhs);

std::ostream operator<< (std::ostream& os, const A& a);
std::ostream operator<< (std::ostream& os, const B& b);

using C = boost::variant<A,B>;

bool f(const A& a1, const A& a2)
{
    return a1 == a2;
}

void g(const A& a1, const A& a2)
{
    BOOST_TEST(a1 == a2);
}

bool f(const C& c1, const C& c2)
{
    return c1 == c2;
}

void g(const C& c1, const C& c2)
{
    BOOST_TEST(c1 == c2);
}

The edited error message is:

error: return type of 'void boost::variant<T0, TN>::operator==(const U&) const [with U = boost::test_tools::assertion::value_expr<const boost::variant<A, B>&>; T0_ = A; TN = {B}]' is not 'bool'
        BOOST_TEST(c1 == c2);
note: used as rewritten candidate for comparison of 'boost::test_tools::assertion::value_expr<const boost::variant<A, B>&>' and 'const C' {aka 'const boost::variant<A, B>'}
/app/boost/include/boost/variant/variant.hpp: In instantiation of 'void boost::variant<T0, TN>::operator==(const U&) const [with U = boost::test_tools::assertion::value_expr<const boost::variant<A, B>&>; T0_ = A; TN = {B}]':
/app/boost/include/boost/variant/variant.hpp:2086:9: error: static assertion failed: false && sizeof(U)
 2086 |         BOOST_STATIC_ASSERT( false && sizeof(U) );

The workaround is to use extra parenthesis in the macro, to avoid the smart decomposition that BOOST_TEST does, but then I loose that smart decomposition.
Also, as seen in the godbolt link, gcc15.2 is able to compile the code correctly, but I cannot update compiler so easily :(

Thanks in advance

Dominant language
C++
Stars
217
Forks
149
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.