1*b2997f57SRichard Smith // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions -Wno-c++2a-extensions
2*b2997f57SRichard Smith // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -Wno-c++2a-extensions
3*b2997f57SRichard Smith // RUN: %clang_cc1 -fsyntax-only -std=c++2a %s -verify
43e308b1fSDouglas Gregor
53e308b1fSDouglas Gregor void print();
63e308b1fSDouglas Gregor
73e308b1fSDouglas Gregor template<typename T, typename... Ts>
print(T first,Ts...rest)83e308b1fSDouglas Gregor void print(T first, Ts... rest) {
93e308b1fSDouglas Gregor (void)first;
103e308b1fSDouglas Gregor print(rest...);
113e308b1fSDouglas Gregor }
123e308b1fSDouglas Gregor
133e308b1fSDouglas Gregor template<typename... Ts>
unexpanded_capture(Ts...values)142589b980SRichard Smith void unexpanded_capture(Ts ...values) {
152589b980SRichard Smith auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}}
163e308b1fSDouglas Gregor }
173e308b1fSDouglas Gregor
183e308b1fSDouglas Gregor template<typename... Ts>
implicit_capture(Ts...values)193e308b1fSDouglas Gregor void implicit_capture(Ts ...values) {
203e308b1fSDouglas Gregor auto implicit = [&] { print(values...); };
213e308b1fSDouglas Gregor implicit();
223e308b1fSDouglas Gregor }
233e308b1fSDouglas Gregor
243e308b1fSDouglas Gregor template<typename... Ts>
do_print(Ts...values)253e308b1fSDouglas Gregor void do_print(Ts... values) {
263e308b1fSDouglas Gregor auto bycopy = [values...]() { print(values...); };
273e308b1fSDouglas Gregor bycopy();
283e308b1fSDouglas Gregor auto byref = [&values...]() { print(values...); };
293e308b1fSDouglas Gregor byref();
303e308b1fSDouglas Gregor
313e308b1fSDouglas Gregor auto bycopy2 = [=]() { print(values...); };
323e308b1fSDouglas Gregor bycopy2();
333e308b1fSDouglas Gregor auto byref2 = [&]() { print(values...); };
343e308b1fSDouglas Gregor byref2();
353e308b1fSDouglas Gregor }
363e308b1fSDouglas Gregor
373e308b1fSDouglas Gregor template void do_print(int, float, double);
383e308b1fSDouglas Gregor
393e308b1fSDouglas Gregor template<typename T, int... Values>
bogus_expansions(T x)403e308b1fSDouglas Gregor void bogus_expansions(T x) {
413e308b1fSDouglas Gregor auto l1 = [x...] {}; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
423e308b1fSDouglas Gregor auto l2 = [Values...] {}; // expected-error{{'Values' in capture list does not name a variable}}
433e308b1fSDouglas Gregor }
443e308b1fSDouglas Gregor
453e308b1fSDouglas Gregor void g(int*, float*, double*);
463e308b1fSDouglas Gregor
473e308b1fSDouglas Gregor template<class... Args>
std_example(Args...args)483e308b1fSDouglas Gregor void std_example(Args... args) {
493e308b1fSDouglas Gregor auto lm = [&, args...] { return g(args...); };
503e308b1fSDouglas Gregor };
513e308b1fSDouglas Gregor
523e308b1fSDouglas Gregor template void std_example(int*, float*, double*);
533e308b1fSDouglas Gregor
543e308b1fSDouglas Gregor template<typename ...Args>
variadic_lambda(Args...args)553e308b1fSDouglas Gregor void variadic_lambda(Args... args) {
563e308b1fSDouglas Gregor auto lambda = [](Args... inner_args) { return g(inner_args...); };
573e308b1fSDouglas Gregor lambda(args...);
583e308b1fSDouglas Gregor }
593e308b1fSDouglas Gregor
603e308b1fSDouglas Gregor template void variadic_lambda(int*, float*, double*);
61ba71c085SRichard Smith
62ba71c085SRichard Smith template<typename ...Args>
init_capture_pack_err(Args...args)63ba71c085SRichard Smith void init_capture_pack_err(Args ...args) {
64*b2997f57SRichard Smith [...as(args)]{} ();
65*b2997f57SRichard Smith [as(args)...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
66*b2997f57SRichard Smith [as...(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
67*b2997f57SRichard Smith [...as{args}]{} ();
68*b2997f57SRichard Smith [as{args}...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
69*b2997f57SRichard Smith [as...{args}]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
70*b2997f57SRichard Smith [...as = args]{} ();
71*b2997f57SRichard Smith [as = args...] {} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
72*b2997f57SRichard Smith [as... = args]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
73*b2997f57SRichard Smith
74*b2997f57SRichard Smith [&...as(args)]{} ();
75*b2997f57SRichard Smith [...&as(args)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
76*b2997f57SRichard Smith
77*b2997f57SRichard Smith [args...] {} ();
78*b2997f57SRichard Smith [...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
79*b2997f57SRichard Smith
80*b2997f57SRichard Smith [&args...] {} ();
81*b2997f57SRichard Smith [...&args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
82*b2997f57SRichard Smith [&...args] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
83ba71c085SRichard Smith }
84ba71c085SRichard Smith
85ba71c085SRichard Smith template<typename ...Args>
init_capture_pack_multi(Args...args)86ba71c085SRichard Smith void init_capture_pack_multi(Args ...args) {
87bb13c9a4SRichard Smith [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}}
88ba71c085SRichard Smith }
89ba71c085SRichard Smith template void init_capture_pack_multi(); // expected-note {{instantiation}}
90ba71c085SRichard Smith template void init_capture_pack_multi(int);
91ba71c085SRichard Smith template void init_capture_pack_multi(int, int); // expected-note {{instantiation}}
92ba71c085SRichard Smith
93ba71c085SRichard Smith template<typename ...Args>
init_capture_pack_outer(Args...args)94ba71c085SRichard Smith void init_capture_pack_outer(Args ...args) {
95ba71c085SRichard Smith print([as(args)] { return sizeof(as); } () ...);
96ba71c085SRichard Smith }
97ba71c085SRichard Smith template void init_capture_pack_outer();
98ba71c085SRichard Smith template void init_capture_pack_outer(int);
99ba71c085SRichard Smith template void init_capture_pack_outer(int, int);
100