blob: 046773f6113d6dfab6dc48ea9ba8b3a5a587ec0c [file] [log] [blame]
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00001// RUN: %clang_cc1 -std=c++1y %s -verify -emit-llvm-only
Richard Smith846f13c2013-09-28 05:23:21 +00002
Richard Smith846f13c2013-09-28 05:23:21 +00003namespace variadic_expansion {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00004 int f(int &, char &) { return 0; }
5 template<class ... Ts> char fv(Ts ... ts) { return 0; }
6 // FIXME: why do we get 2 error messages
7 template <typename ... T> void g(T &... t) { //expected-note3{{declared here}}
Richard Smith846f13c2013-09-28 05:23:21 +00008 f([&a(t)]()->decltype(auto) {
9 return a;
10 }() ...);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011
12 auto L = [x = f([&a(t)]()->decltype(auto) { return a; }()...)]() { return x; };
13 const int y = 10;
14 auto M = [x = y,
15 &z = y](T& ... t) { };
16 auto N = [x = y,
17 &z = y, n = f(t...),
18 o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...), t...](T& ... s) {
19 fv([&a(t)]()->decltype(auto) {
20 return a;
21 }() ...);
22 };
23 auto N2 = [x = y, //expected-note3{{begins here}}
24 &z = y, n = f(t...),
25 o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...)](T& ... s) {
26 fv([&a(t)]()->decltype(auto) { //expected-error 3{{captured}}
27 return a;
28 }() ...);
29 };
30
Richard Smith846f13c2013-09-28 05:23:21 +000031 }
32
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000033 void h(int i, char c) { g(i, c); } //expected-note{{in instantiation}}
Richard Smith846f13c2013-09-28 05:23:21 +000034}
Faisal Vali5ab61b02013-12-08 15:00:29 +000035namespace simple_init_captures {
36 void test() {
37 int i;
38 auto L = [i](auto a) { return i + a; };
39 L(3.14);
40 }
41}
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000042
43namespace odr_use_within_init_capture {
44
45int test() {
Faisal Vali5ab61b02013-12-08 15:00:29 +000046
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000047 { // no captures
48 const int x = 10;
49 auto L = [z = x + 2](int a) {
50 auto M = [y = x - 2](char b) {
51 return y;
52 };
53 return M;
54 };
55
56 }
57 { // should not capture
58 const int x = 10;
59 auto L = [&z = x](int a) {
60 return a;;
61 };
62
63 }
64 {
65 const int x = 10;
66 auto L = [k = x](char a) { //expected-note {{declared}}
67 return [](int b) { //expected-note {{begins}}
68 return [j = k](int c) { //expected-error {{cannot be implicitly captured}}
69 return c;
70 };
71 };
72 };
73 }
74 {
75 const int x = 10;
76 auto L = [k = x](char a) {
77 return [=](int b) {
78 return [j = k](int c) {
79 return c;
80 };
81 };
82 };
83 }
84 {
85 const int x = 10;
86 auto L = [k = x](char a) {
87 return [k](int b) {
88 return [j = k](int c) {
89 return c;
90 };
91 };
92 };
93 }
94
95 return 0;
96}
97
98int run = test();
99
100}
101
102namespace odr_use_within_init_capture_template {
103
104template<class T = int>
105int test(T t = T{}) {
106
107 { // no captures
108 const T x = 10;
109 auto L = [z = x](char a) {
110 auto M = [y = x](T b) {
111 return y;
112 };
113 return M;
114 };
115
116 }
117 { // should not capture
118 const T x = 10;
119 auto L = [&z = x](T a) {
120 return a;;
121 };
122
123 }
124 { // will need to capture x in outer lambda
125 const T x = 10; //expected-note {{declared}}
126 auto L = [z = x](char a) { //expected-note {{begins}}
127 auto M = [&y = x](T b) { //expected-error {{cannot be implicitly captured}}
128 return y;
129 };
130 return M;
131 };
132
133 }
134 { // will need to capture x in outer lambda
135 const T x = 10;
136 auto L = [=,z = x](char a) {
137 auto M = [&y = x](T b) {
138 return y;
139 };
140 return M;
141 };
142
143 }
144 { // will need to capture x in outer lambda
145 const T x = 10;
146 auto L = [x, z = x](char a) {
147 auto M = [&y = x](T b) {
148 return y;
149 };
150 return M;
151 };
152 }
153 { // will need to capture x in outer lambda
154 const int x = 10; //expected-note 2{{declared}}
155 auto L = [z = x](char a) { //expected-note 2{{begins}}
156 auto M = [&y = x](T b) { //expected-error 2{{cannot be implicitly captured}}
157 return y;
158 };
159 return M;
160 };
161 }
162 {
163 // no captures
164 const T x = 10;
165 auto L = [z =
166 [z = x, &y = x](char a) { return z + y; }('a')](char a)
167 { return z; };
168
169 }
170
171 return 0;
172}
173
174int run = test(); //expected-note {{instantiation}}
175
176}