1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions -Wno-c++2a-extensions 2 // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -Wno-c++2a-extensions 3 // RUN: %clang_cc1 -fsyntax-only -std=c++2a %s -verify 4 5 void print(); 6 7 template<typename T, typename... Ts> 8 void print(T first, Ts... rest) { 9 (void)first; 10 print(rest...); 11 } 12 13 template<typename... Ts> 14 void unexpanded_capture(Ts ...values) { 15 auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}} 16 } 17 18 template<typename... Ts> 19 void implicit_capture(Ts ...values) { 20 auto implicit = [&] { print(values...); }; 21 implicit(); 22 } 23 24 template<typename... Ts> 25 void do_print(Ts... values) { 26 auto bycopy = [values...]() { print(values...); }; 27 bycopy(); 28 auto byref = [&values...]() { print(values...); }; 29 byref(); 30 31 auto bycopy2 = [=]() { print(values...); }; 32 bycopy2(); 33 auto byref2 = [&]() { print(values...); }; 34 byref2(); 35 } 36 37 template void do_print(int, float, double); 38 39 template<typename T, int... Values> 40 void bogus_expansions(T x) { 41 auto l1 = [x...] {}; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} 42 auto l2 = [Values...] {}; // expected-error{{'Values' in capture list does not name a variable}} 43 } 44 45 void g(int*, float*, double*); 46 47 template<class... Args> 48 void std_example(Args... args) { 49 auto lm = [&, args...] { return g(args...); }; 50 }; 51 52 template void std_example(int*, float*, double*); 53 54 template<typename ...Args> 55 void variadic_lambda(Args... args) { 56 auto lambda = [](Args... inner_args) { return g(inner_args...); }; 57 lambda(args...); 58 } 59 60 template void variadic_lambda(int*, float*, double*); 61 62 template<typename ...Args> 63 void init_capture_pack_err(Args ...args) { 64 [...as(args)]{} (); 65 [as(args)...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 66 [as...(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 67 [...as{args}]{} (); 68 [as{args}...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 69 [as...{args}]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 70 [...as = args]{} (); 71 [as = args...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 72 [as... = args]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 73 74 [&...as(args)]{} (); 75 [...&as(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}} 76 77 [args...] {} (); 78 [...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}} 79 80 [&args...] {} (); 81 [...&args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}} 82 [&...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}} 83 } 84 85 template<typename ...Args> 86 void init_capture_pack_multi(Args ...args) { 87 [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}} 88 } 89 template void init_capture_pack_multi(); // expected-note {{instantiation}} 90 template void init_capture_pack_multi(int); 91 template void init_capture_pack_multi(int, int); // expected-note {{instantiation}} 92 93 template<typename ...Args> 94 void init_capture_pack_outer(Args ...args) { 95 print([as(args)] { return sizeof(as); } () ...); 96 } 97 template void init_capture_pack_outer(); 98 template void init_capture_pack_outer(int); 99 template void init_capture_pack_outer(int, int); 100