// { dg-additional-options "-std=c++14 -Wno-return-type" } template class function; template class invoker_base { public: virtual ~invoker_base() { } }; template class functor_invoker : public invoker_base { public: explicit functor_invoker(const F& f) : f(f) { } private: F f; }; template class function { public: template function(const F& f) : invoker(0) { invoker = new functor_invoker(f); } ~function() { if (invoker) delete invoker; } private: invoker_base* invoker; }; template struct unique_ptr { }; struct A {}; template struct typelist {}; template unique_ptr chooseB(typelist); template unique_ptr chooseB(typelist choices, Idx, Rest... rest) { auto f = [=](auto) { return [=] { return chooseB(choices, rest...); }; }; function()> fs[]{f(Cs{})...}; } main() { chooseB(typelist{}, 0, 1, 2); }