trompeloeil
trompeloeil copied to clipboard
Compilation error with clang17 and std::expected
Please, help to resolve compilation error I got when I started to use trompeloeil.
#include <trompeloeil.hpp>
#include <expected>
#include <string>
using Return = std::expected<int, std::string>;
struct Interface {
virtual Return foo() = 0;
};
struct Mock: trompeloeil::mock_interface<Interface> {
IMPLEMENT_MOCK0(foo);
};
int main()
{
{
Mock mock;
REQUIRE_CALL(mock, foo())
.RETURN(Return{});
mock.foo();
}
}
The list of errors is huge but the small extract is
<source>:19:10: note: in instantiation of function template specialization 'trompeloeil::call_modifier<trompeloeil::call_matcher<std::expected<int, std::string> (), std::tuple<>>, Mock::trompeloeil_l_tag_type_trompeloeil_11, trompeloeil::matcher_info<std::expected<int, std::string> ()>>::action<trompeloeil::handle_return, (lambda at <source>:19:10)>' requested here
19 | .RETURN(Return{});
| ^
https://godbolt.org/z/sMe6PoYWc
I wrote a patch for 47 version. Maybe it will help to make the imrovements trompeloeil.patch
Man, that is nasty. IMO operator==(expected<T,E>, V) should only be a candidate if T and V are equality comparable. I'm not sure if this should be a defect report to the standard, or a bug report to the library. I notice that gcc's libstdc++ has the same problem as libc++.
Thanks for the patch.
Please try out branch expected and see if it solves your issue.
Man, thank you, it works now!
I'd suggest you to extend your tests as I wrote in the comments.
Please let me know when the fix appears in the release.
Added the test you suggested. Thanks.
Merged to main. I'm off to the C++OnSea conference in the UK next week, so it'll probably be some time after that that I tag the next release.
Just tagged release v48 which includes this.