trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

Compilation error with clang17 and std::expected

Open subbota-a opened this issue 1 year ago • 4 comments

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

subbota-a avatar Jun 27 '24 06:06 subbota-a

I wrote a patch for 47 version. Maybe it will help to make the imrovements trompeloeil.patch

subbota-a avatar Jun 27 '24 08:06 subbota-a

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.

rollbear avatar Jun 30 '24 07:06 rollbear

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.

subbota-a avatar Jun 30 '24 08:06 subbota-a

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.

rollbear avatar Jun 30 '24 12:06 rollbear

Just tagged release v48 which includes this.

rollbear avatar Jul 14 '24 08:07 rollbear