A lambda captures h , which has a potentially throwing destructor, so the lambda closure type also has a potentially throwing destructor.
With this in mind, you can reduce the problem to this:
#include <functional> struct F { void operator()() { } ~F() noexcept(false) {} }; int main() { std::function<void ()> f = F{}; }
It appears that std::function in libC ++ cannot store the type being called without the nothrow destructor, which looks like an error in libC ++.
From the error messages, it seems that fixing can be as simple as adding an explicit noexcept to the __func destructor, but I am not familiar with the implementation, so it may not be so simple.
I do not see any obvious workarounds, except that you transfer your Hndl type to another type using the noexcept destructor, so grabbing it in lambda does not make the lambda does not have a noexcept(false) destructor. I tried something like this, but libC ++ seems to have similar problems in shared_ptr :
std::function<void ()> f = std::bind(&Hndl::operator(), std::make_shared<Hndl>());
source share