Sample code adapted from https://adishavit.github.io/2016/Technical-Debt/ (https://godbolt.org/g/osKPbq): void f(void (*f1)(int)) { f1(42); } //Converts any lambda to a captureless lambda that converts nicely to a function pointer for the lifetime of the temporary. template <typename Lambda> static auto callback(Lambda &&l) { static auto* p = &l; p = &l; return [](auto... x){ return (*p)(x...); }; } int main() { int x = 5; f(callback([=](int y){std::cout << x << ' ' << y;})); } Gives the error: <source>: In instantiation of 'callback(Lambda&&)::<lambda(auto:1 ...)> [with auto:1 = {int}; Lambda = main()::<lambda(int)>]': <source>:14:22: required by substitution of 'template<class ... auto:1> callback(Lambda&&) [with Lambda = main()::<lambda(int)>]::<lambda(auto:1 ...)>::operator decltype (((const callback(Lambda&&) [with Lambda = main()::<lambda(int)>]::<lambda(auto:1 ...)>*)((const callback(Lambda&&) [with Lambda = main()::<lambda(int)>]::<lambda(auto:1 ...)>* const)0u))->operator()(static_cast<auto:1&>(callback::__lambda0<main::__lambda1>::_FUN::<unnamed>) ...)) (*)(auto:1 ...)() const [with auto:1 = {int}]' <source>:19:54: required from here <source>:14:33: error: use of 'p' before deduction of 'auto' return [](auto... x){ return (*p)(x...); }; ~^~~ <source>:14:36: error: invalid use of 'auto' return [](auto... x){ return (*p)(x...); }; ~~~~^~~~~~ Making the lambda in callback non-generic(ie: [](int x){return (*p)(x);}) or explicitly calculating the type of p(std::add_pointer_t<decltype(l)>) makes the code compile successfully.
Author: paolo Date: Wed Oct 4 08:34:40 2017 New Revision: 253397 URL: https://gcc.gnu.org/viewcvs?rev=253397&root=gcc&view=rev Log: 2017-10-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/78816 * g++.dg/cpp1y/lambda-generic-variadic6.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C Modified: trunk/gcc/testsuite/ChangeLog
Fixed in trunk.