Problem using BOOST_TEST(a==b) to compare boost::variant in gcc12 in C++20 mode
- Dominant language
- C++
- Stars
- 213
- Forks
- 149
- Avg merge
- 18h 17m
- Merged PRs (30d)
- 2
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
#include
#include
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;
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::operator==(const U&) const [with U = boost::test_tools::assertion::value_expr&>; 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&>' and 'const C' {aka 'const boost::variant'}
/app/boost/include/boost/variant/variant.hpp: In instantiation of 'void boost::variant::operator==(const U&) const [with U = boost::test_tools::assertion::value_expr&>; 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.