blob: 174ae6d5b09f604c3ca78183a4e12d2d341ede9f [file] [log] [blame]
Douglas Gregor3e308b12012-02-14 19:27:52 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
Richard Smithba71c082013-05-16 06:20:58 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
Douglas Gregor3e308b12012-02-14 19:27:52 +00003
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>
Richard Smith2589b9802012-07-25 03:56:55 +000013void unexpanded_capture(Ts ...values) {
14 auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}}
Douglas Gregor3e308b12012-02-14 19:27:52 +000015}
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*);
Richard Smithba71c082013-05-16 06:20:58 +000060
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}} 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);