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
7 template<typename T
, typename
... Ts
>
8 void print(T first
, Ts
... rest
) {
13 template<typename
... Ts
>
14 void unexpanded_capture(Ts
...values
) {
15 auto unexp
= [values
] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}}
18 template<typename
... Ts
>
19 void implicit_capture(Ts
...values
) {
20 auto implicit
= [&] { print(values
...); };
24 template<typename
... Ts
>
25 void do_print(Ts
... values
) {
26 auto bycopy
= [values
...]() { print(values
...); };
28 auto byref
= [&values
...]() { print(values
...); };
31 auto bycopy2
= [=]() { print(values
...); };
33 auto byref2
= [&]() { print(values
...); };
37 template void do_print(int, float, double);
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}}
45 void g(int*, float*, double*);
47 template<class... Args
>
48 void std_example(Args
... args
) {
49 auto lm
= [&, args
...] { return g(args
...); };
52 template void std_example(int*, float*, double*);
54 template<typename
...Args
>
55 void variadic_lambda(Args
... args
) {
56 auto lambda
= [](Args
... inner_args
) { return g(inner_args
...); };
60 template void variadic_lambda(int*, float*, double*);
62 template<typename
...Args
>
63 void init_capture_pack_err(Args
...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}}
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}}
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}}
75 [...&as(args
)]{} (); // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
78 [...args
] {} (); // expected-error {{ellipsis in pack capture must appear after the name of the capture}}
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}}
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}}
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}}
93 template<typename
...Args
>
94 void init_capture_pack_outer(Args
...args
) {
95 print([as(args
)] { return sizeof(as
); } () ...);
97 template void init_capture_pack_outer();
98 template void init_capture_pack_outer(int);
99 template void init_capture_pack_outer(int, int);