Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -18872,8 +18872,8 @@ } FunctionScopeInfo *FSI = FunctionScopes[FunctionScopesIndex]; - CapturingScopeInfo *CSI = cast(FSI); - + CapturingScopeInfo *CSI = dyn_cast(FSI); + if (!CSI) return true; // Check whether we've already captured it. if (isVariableAlreadyCapturedInScopeInfo(CSI, Var, Nested, CaptureType, Index: clang/test/SemaTemplate/lambda-variadic.cpp =================================================================== --- /dev/null +++ clang/test/SemaTemplate/lambda-variadic.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused-value +// expected-no-diagnostics +namespace test1 { + +template int return_num() { return num; } + +template struct lambda_wrapper { + lambda &outer_lambda; + lambda_wrapper(lambda& outer_lambda) : outer_lambda(outer_lambda) {} + template auto operator+(T t) { outer_lambda(t); return 1; } +}; + +template +void bw(lambda& outer_lambda) { + (lambda_wrapper(outer_lambda) + ... + return_num()); +} + +template auto check_return_type(lambda inner_lambda) { + using inner_lambda_return_type = decltype(inner_lambda(5)); +} + +void cs() { + auto outer_lambda = [](auto param) { + auto inner_lambda = [](auto o) -> decltype(param) {}; + check_return_type(inner_lambda); + }; + bw<1,2>(outer_lambda); +} + +} // namespace test1 + +namespace test2 { + +template +auto run_lambda_with_zero(lambda l) { + l(0); +} +template +void run_lambda_once_per_type(lambda l) { + ((Ts{}, run_lambda_with_zero(l)), ...); +} +template void inner_function() { + char c; + [](auto param) -> decltype(c) { return param; }(0); +} +void run() { + auto x = [](auto) -> void { inner_function(); }; + run_lambda_once_per_type(x); +} + +} // namespace test2