Open SeverinTobler opened 1 year ago
I suggest to solve this issue by adding enable_if
to the comparison operators, to propagate the comparison trait of T
and U
to the tl::optional
comparison operators.
I seem to have the same or a similar issue. Is there a workaround for this as long as this has not been addressed?
class SomeMock {
MAKE_MOCK0 (someFunctionReturnTlOptional, tl::optional<std::string>());
};
TEST_CASE("my test") {
tl::optional<std::string> myTlOptional = "some string";
SomeMock someMock;
ALLOW_CALL(someMock, someFunctionReturningTlOptional()).RETURN(myTlOptional);
}
Then compiler says:
optional/include/tl/optional.hpp:1425:33: error: invalid operands to binary expression ('const std::string' and 'const std::nullptr_t')
return lhs.has_value() ? *lhs == rhs : false;
The referenced code @ optional.hpp:1425 is:
template <class T, class U>
inline constexpr bool operator==(const optional<T> &lhs, const U &rhs) {
return lhs.has_value() ? *lhs == rhs : false;
}
Checking with templates whether
tl::optional<T>
is comparable returns the wrong result, ifT
is not comparable (check works withstd::optional
). For example:Note: I ran into this issue using
tl::optional
with Trompeloil (https://github.com/rollbear/trompeloeil), as Trompeloil checks this way whether function parameters are comparable tonullptr
.