Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed requirement is_swappable, enable_if cannot be used to disable unexpected_type::swap #50

Closed
negatratoron opened this issue Nov 2, 2022 · 0 comments

Comments

@negatratoron
Copy link

When I compile the following code with expected.hpp 0.6.2, where the class is not movable because a const member causes the move constructor to be deleted

#include "expected.hpp"

struct Foo {
  Foo(int x_) : x(x_) {}
  const int x;
  Foo(Foo const&) = default;
};

int main() {
  auto x = nonstd::make_unexpected<Foo>(Foo(3));
}

I get the following error on clang++ 14.0.6

In file included from main.cpp:1:
./expected.hpp:1006:9: error: failed requirement 'std17::is_swappable<Foo>::value'; 'enable_if' cannot be used to disable this declaration
        std17::is_swappable<E>::value
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./expected.hpp:314:31: note: expanded from macro 'nsel_REQUIRES_R'
    typename std::enable_if< (__VA_ARGS__), R>::type
                              ^~~~~~~~~~~
./expected.hpp:1176:1: note: in instantiation of template class 'nonstd::expected_lite::unexpected_type<Foo>' requested here
make_unexpected( E && value ) -> unexpected_type< typename std::decay<E>::type >
^
main.cpp:10:20: note: in instantiation of function template specialization 'nonstd::expected_lite::make_unexpected<Foo>' requested here
  auto x = nonstd::make_unexpected<Foo>(Foo(3));
                   ^
1 error generated.

The 'enable_if' cannot be used to disable this declaration makes this seem like a bug. If I delete the swap declaration from expected.hpp:1006, my code compiles.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant