Opened 7 years ago
Closed 3 years ago
#11941 closed Bugs (wontfix)
Use of overloaded operator== in BOOST_TEST() is ambiguous
| Reported by: | Owned by: | Gennadiy Rozental | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | test |
| Version: | Boost 1.59.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
I'm unable to compile the following code due to ambiguity of opertor== overloads.
#define BOOST_TEST_MODULE mytest
#include <boost/test/included/unit_test.hpp>
struct S {
template <class T>
S(T&&) {}
};
bool operator==(S const&, S const&) { return true; }
template <class T>
bool operator==(T const&, S const&) { return true; }
BOOST_AUTO_TEST_CASE(test1)
{
auto const s = S{"hoge"};
BOOST_TEST(s == 4);
}
This seems to happen if there is an overload taking a template parameter for the left operand.
Using boost::iterator_range, instead of the class S, results in same issue.
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 3 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Workaround mentioned in the documentation of BOOST_TEST
Note:
See TracTickets
for help on using tickets.

I do not think we can do anything about this. Templated operator== will always conflict with my templated operator== method.
You can alway work around the issue with pair of extra ().