expected icon indicating copy to clipboard operation
expected copied to clipboard

User-provided move constructor issue

Open sparik opened this issue 4 years ago • 0 comments

Hi.

Looks like if a type is not trivially move-constructible, then tl::expected<T, ...> is not move-constructible at all. Is this behavior intended?

Here is an example tested with the current master branch and gcc 11.1

#include "expected.hpp"

struct user_provided_move {
        user_provided_move() = default;
        user_provided_move(user_provided_move&&) noexcept {}
};

struct defaulted_move {
        defaulted_move() = default;
        defaulted_move(defaulted_move&&) noexcept = default;
};

int main() {
        tl::expected<user_provided_move, int> t1;
        tl::expected<defaulted_move, int> t2;
        
        tl::expected<user_provided_move, int> tm1(std::move(t1));
        tl::expected<defaulted_move, int> tm2(std::move(t2)); // does not compile
}

sparik avatar Dec 22 '21 15:12 sparik