1*d6ae4bd6SCorentin Jabot // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused-value -std=c++17 2*d6ae4bd6SCorentin Jabot // expected-no-diagnostics 3*d6ae4bd6SCorentin Jabot namespace test1 { 4*d6ae4bd6SCorentin Jabot return_num()5*d6ae4bd6SCorentin Jabottemplate <int num> int return_num() { return num; } 6*d6ae4bd6SCorentin Jabot 7*d6ae4bd6SCorentin Jabot template <typename lambda> struct lambda_wrapper { 8*d6ae4bd6SCorentin Jabot lambda &outer_lambda; lambda_wrappertest1::lambda_wrapper9*d6ae4bd6SCorentin Jabot lambda_wrapper(lambda& outer_lambda) : outer_lambda(outer_lambda) {} operator +test1::lambda_wrapper10*d6ae4bd6SCorentin Jabot template <typename T> auto operator+(T t) { outer_lambda(t); return 1; } 11*d6ae4bd6SCorentin Jabot }; 12*d6ae4bd6SCorentin Jabot 13*d6ae4bd6SCorentin Jabot template <int... nums, typename lambda> bw(lambda & outer_lambda)14*d6ae4bd6SCorentin Jabotvoid bw(lambda& outer_lambda) { 15*d6ae4bd6SCorentin Jabot (lambda_wrapper(outer_lambda) + ... + return_num<nums>()); 16*d6ae4bd6SCorentin Jabot } 17*d6ae4bd6SCorentin Jabot check_return_type(lambda inner_lambda)18*d6ae4bd6SCorentin Jabottemplate <typename lambda> auto check_return_type(lambda inner_lambda) { 19*d6ae4bd6SCorentin Jabot using inner_lambda_return_type = decltype(inner_lambda(5)); 20*d6ae4bd6SCorentin Jabot } 21*d6ae4bd6SCorentin Jabot cs()22*d6ae4bd6SCorentin Jabotvoid cs() { 23*d6ae4bd6SCorentin Jabot auto outer_lambda = [](auto param) { 24*d6ae4bd6SCorentin Jabot auto inner_lambda = [](auto o) -> decltype(param) {}; 25*d6ae4bd6SCorentin Jabot check_return_type(inner_lambda); 26*d6ae4bd6SCorentin Jabot }; 27*d6ae4bd6SCorentin Jabot bw<1,2>(outer_lambda); 28*d6ae4bd6SCorentin Jabot } 29*d6ae4bd6SCorentin Jabot 30*d6ae4bd6SCorentin Jabot } // namespace test1 31*d6ae4bd6SCorentin Jabot 32*d6ae4bd6SCorentin Jabot namespace test2 { 33*d6ae4bd6SCorentin Jabot 34*d6ae4bd6SCorentin Jabot template <typename lambda> run_lambda_with_zero(lambda l)35*d6ae4bd6SCorentin Jabotauto run_lambda_with_zero(lambda l) { 36*d6ae4bd6SCorentin Jabot l(0); 37*d6ae4bd6SCorentin Jabot } 38*d6ae4bd6SCorentin Jabot template <typename ... Ts, typename lambda> run_lambda_once_per_type(lambda l)39*d6ae4bd6SCorentin Jabotvoid run_lambda_once_per_type(lambda l) { 40*d6ae4bd6SCorentin Jabot ((Ts{}, run_lambda_with_zero(l)), ...); 41*d6ae4bd6SCorentin Jabot } inner_function()42*d6ae4bd6SCorentin Jabottemplate <typename> void inner_function() { 43*d6ae4bd6SCorentin Jabot char c; 44*d6ae4bd6SCorentin Jabot [](auto param) -> decltype(c) { return param; }(0); 45*d6ae4bd6SCorentin Jabot } run()46*d6ae4bd6SCorentin Jabotvoid run() { 47*d6ae4bd6SCorentin Jabot auto x = [](auto) -> void { inner_function<int>(); }; 48*d6ae4bd6SCorentin Jabot run_lambda_once_per_type<int>(x); 49*d6ae4bd6SCorentin Jabot } 50*d6ae4bd6SCorentin Jabot 51*d6ae4bd6SCorentin Jabot } // namespace test2 52