Problem using BOOST_TEST(a==b) to compare boost::variant in gcc12 in C++20 mode
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/test
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Conversion Warning with GCC15 when using operator<< within custom failure message and -WConversionOpen
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Qiskit/qiskit-aer#2466 ·
-
feature request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
status:needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
PX4/PX4-Autopilot#29006 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Segfault in pwStreamAddBuffer: createBuffer() returning nullptr is dereferenced (Screencopy.cpp:943)Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100