Segmentation fault when using std::variant with std::visit and lambda capturing non-copyable types
I'm working with a segmentation fault when trying to use `std::variant` in combination with `std::visit` and a lambda that captures a non-copyable type. I have a simple example below: ```cpp #include <iostream> #include <variant> #include <memory> struct NonCopyable { NonCopyable() = default; NonCopyable(const NonCopyable&) = delete; NonCopyable(NonCopyable&&) = default; }; using MyVariant = std::variant<int, std::unique_ptr<NonCopyable>>; void handleVariant(const MyVariant& v) { std::visit([](auto&& arg) { // Capturing non-copyable type NonCopyable nc; std::cout << arg << " captured non-copyable type\n"; }, v); } int main() { MyVariant var = std::make_unique<NonCopyable>(); handleVariant(var); return 0; } ``` When I run this code, I get a segmentation fault at runtime. I suspect that it's due to my lambda trying to capture a `NonCopyable` instance, which doesn't seem to play well with the way `std::visit` works. I've tried changing the lambda capture to pass-by-value, but that doesn't help as `NonCopyable` need to be copied. Is there a way to properly handle this situation without running into segmentation faults? Any insights would be greatly appreciated.