1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions |
2 | // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify |
3 | |
4 | void print(); |
5 | |
6 | template<typename T, typename... Ts> |
7 | void print(T first, Ts... rest) { |
8 | (void)first; |
9 | print(rest...); |
10 | } |
11 | |
12 | template<typename... Ts> |
13 | void unexpanded_capture(Ts ...values) { |
14 | auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}} |
15 | } |
16 | |
17 | template<typename... Ts> |
18 | void implicit_capture(Ts ...values) { |
19 | auto implicit = [&] { print(values...); }; |
20 | implicit(); |
21 | } |
22 | |
23 | template<typename... Ts> |
24 | void 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 | |
36 | template void do_print(int, float, double); |
37 | |
38 | template<typename T, int... Values> |
39 | void 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 | |
44 | void g(int*, float*, double*); |
45 | |
46 | template<class... Args> |
47 | void std_example(Args... args) { |
48 | auto lm = [&, args...] { return g(args...); }; |
49 | }; |
50 | |
51 | template void std_example(int*, float*, double*); |
52 | |
53 | template<typename ...Args> |
54 | void variadic_lambda(Args... args) { |
55 | auto lambda = [](Args... inner_args) { return g(inner_args...); }; |
56 | lambda(args...); |
57 | } |
58 | |
59 | template void variadic_lambda(int*, float*, double*); |
60 | |
61 | template<typename ...Args> |
62 | void init_capture_pack_err(Args ...args) { |
63 | [as(args)...] {} (); // expected-error {{expected ','}} |
64 | [as...(args)]{} (); // expected-error {{expected ','}} |
65 | } |
66 | |
67 | template<typename ...Args> |
68 | void init_capture_pack_multi(Args ...args) { |
69 | [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}} |
70 | } |
71 | template void init_capture_pack_multi(); // expected-note {{instantiation}} |
72 | template void init_capture_pack_multi(int); |
73 | template void init_capture_pack_multi(int, int); // expected-note {{instantiation}} |
74 | |
75 | template<typename ...Args> |
76 | void init_capture_pack_outer(Args ...args) { |
77 | print([as(args)] { return sizeof(as); } () ...); |
78 | } |
79 | template void init_capture_pack_outer(); |
80 | template void init_capture_pack_outer(int); |
81 | template void init_capture_pack_outer(int, int); |
82 | |