ned14 / outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
https://ned14.github.io/outcome
Other
675 stars 62 forks source link

Compile error with move-only custom payload and void value type #291

Closed gix closed 7 months ago

gix commented 7 months ago

Given the following custom error code:

struct MovableError
{
    MovableError() = default;
    MovableError(MovableError&&) = default;
    MovableError& operator=(MovableError&&) = default;
};

std::error_code make_error_code(MovableError const& error);
void outcome_throw_as_system_error_with_payload(MovableError error);

template<typename T>
using MyResult = result<T, MovableError>;

MyResult<int> f();
MyResult<void> g();

f().value() compiles, but g().value() does not. It wants to copy MovableError when calling outcome_throw_as_system_error_with_payload since the Impl passed to wide_value_check is const.

Looks like the void-specialization of basic_result_value_observers is missing a non-const value() overload.

ned14 commented 7 months ago

Verified: https://godbolt.org/z/Y85hYz71b

Thanks for the BR!

ned14 commented 7 months ago

This is fixed in develop branch, I'll seek permission to get it into the Boost 1.84 release which is currently within release cycle.

Thanks for the BR, it's interesting four years passed before anybody noticed this!