failed requirement is_swappable, enable_if cannot be used to disable unexpected_type::swap
negatratoron opened this issue · 0 comments
negatratoron commented
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!