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