100 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions -Wno-c++2a-extensions2// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -Wno-c++2a-extensions3// RUN: %clang_cc1 -fsyntax-only -std=c++2a %s -verify4 5void print();6 7template<typename T, typename... Ts>8void print(T first, Ts... rest) {9 (void)first;10 print(rest...);11}12 13template<typename... Ts>14void unexpanded_capture(Ts ...values) {15 auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}}16}17 18template<typename... Ts>19void implicit_capture(Ts ...values) {20 auto implicit = [&] { print(values...); };21 implicit();22}23 24template<typename... Ts>25void 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 37template void do_print(int, float, double);38 39template<typename T, int... Values>40void 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 45void g(int*, float*, double*);46 47template<class... Args>48void std_example(Args... args) {49 auto lm = [&, args...] { return g(args...); };50};51 52template void std_example(int*, float*, double*);53 54template<typename ...Args>55void variadic_lambda(Args... args) {56 auto lambda = [](Args... inner_args) { return g(inner_args...); };57 lambda(args...);58}59 60template void variadic_lambda(int*, float*, double*);61 62template<typename ...Args>63void 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 85template<typename ...Args>86void init_capture_pack_multi(Args ...args) {87 [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}}88}89template void init_capture_pack_multi(); // expected-note {{instantiation}}90template void init_capture_pack_multi(int);91template void init_capture_pack_multi(int, int); // expected-note {{instantiation}}92 93template<typename ...Args>94void init_capture_pack_outer(Args ...args) {95 print([as(args)] { return sizeof(as); } () ...);96}97template void init_capture_pack_outer();98template void init_capture_pack_outer(int);99template void init_capture_pack_outer(int, int);100