1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -emit-llvm-only %s
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
3f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
4f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
5f4a2713aSLionel Sambuc
6*0a6a1f1dSLionel Sambuc template<class F, class ...Rest> struct first_impl { typedef F type; };
7*0a6a1f1dSLionel Sambuc template<class ...Args> using first = typename first_impl<Args...>::type;
8*0a6a1f1dSLionel Sambuc
9*0a6a1f1dSLionel Sambuc namespace simple_explicit_capture {
test()10*0a6a1f1dSLionel Sambuc void test() {
11*0a6a1f1dSLionel Sambuc int i;
12*0a6a1f1dSLionel Sambuc auto L = [i](auto a) { return i + a; };
13*0a6a1f1dSLionel Sambuc L(3.14);
14*0a6a1f1dSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc }
16*0a6a1f1dSLionel Sambuc
17f4a2713aSLionel Sambuc namespace explicit_call {
test()18f4a2713aSLionel Sambuc int test() {
19f4a2713aSLionel Sambuc auto L = [](auto a) { return a; };
20f4a2713aSLionel Sambuc L.operator()(3);
21f4a2713aSLionel Sambuc L.operator()<char>(3.14); //expected-warning{{implicit conversion}}
22f4a2713aSLionel Sambuc return 0;
23f4a2713aSLionel Sambuc }
24f4a2713aSLionel Sambuc } //end ns
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc namespace test_conversion_to_fptr_2 {
27f4a2713aSLionel Sambuc
28f4a2713aSLionel Sambuc template<class T> struct X {
29f4a2713aSLionel Sambuc
__anon001ec7460302test_conversion_to_fptr_2::X30f4a2713aSLionel Sambuc T (*fp)(T) = [](auto a) { return a; };
31f4a2713aSLionel Sambuc
32f4a2713aSLionel Sambuc };
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc X<int> xi;
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc template<class T>
__anon001ec7460402(auto a) 37f4a2713aSLionel Sambuc void fooT(T t, T (*fp)(T) = [](auto a) { return a; }) {
38f4a2713aSLionel Sambuc fp(t);
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc
test()41f4a2713aSLionel Sambuc int test() {
42f4a2713aSLionel Sambuc {
43f4a2713aSLionel Sambuc auto L = [](auto a) { return a; };
44f4a2713aSLionel Sambuc int (*fp)(int) = L;
45f4a2713aSLionel Sambuc fp(5);
46f4a2713aSLionel Sambuc L(3);
47f4a2713aSLionel Sambuc char (*fc)(char) = L;
48f4a2713aSLionel Sambuc fc('b');
49f4a2713aSLionel Sambuc L('c');
50f4a2713aSLionel Sambuc double (*fd)(double) = L;
51f4a2713aSLionel Sambuc fd(3.14);
52f4a2713aSLionel Sambuc fd(6.26);
53f4a2713aSLionel Sambuc L(4.25);
54f4a2713aSLionel Sambuc }
55f4a2713aSLionel Sambuc {
56f4a2713aSLionel Sambuc auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
57f4a2713aSLionel Sambuc int (*fp)(int) = L;
58f4a2713aSLionel Sambuc char (*fc)(char) = L; //expected-error{{no viable conversion}}
59f4a2713aSLionel Sambuc double (*fd)(double) = L; //expected-error{{no viable conversion}}
60f4a2713aSLionel Sambuc }
61f4a2713aSLionel Sambuc {
62f4a2713aSLionel Sambuc int x = 5;
63f4a2713aSLionel Sambuc auto L = [=](auto b, char c = 'x') {
64f4a2713aSLionel Sambuc int i = x;
65f4a2713aSLionel Sambuc return [](auto a) ->decltype(a) { return a; };
66f4a2713aSLionel Sambuc };
67f4a2713aSLionel Sambuc int (*fp)(int) = L(8);
68f4a2713aSLionel Sambuc fp(5);
69f4a2713aSLionel Sambuc L(3);
70f4a2713aSLionel Sambuc char (*fc)(char) = L('a');
71f4a2713aSLionel Sambuc fc('b');
72f4a2713aSLionel Sambuc L('c');
73f4a2713aSLionel Sambuc double (*fd)(double) = L(3.14);
74f4a2713aSLionel Sambuc fd(3.14);
75f4a2713aSLionel Sambuc fd(6.26);
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc }
78f4a2713aSLionel Sambuc {
79f4a2713aSLionel Sambuc auto L = [=](auto b) {
80f4a2713aSLionel Sambuc return [](auto a) ->decltype(b)* { return (decltype(b)*)0; };
81f4a2713aSLionel Sambuc };
82f4a2713aSLionel Sambuc int* (*fp)(int) = L(8);
83f4a2713aSLionel Sambuc fp(5);
84f4a2713aSLionel Sambuc L(3);
85f4a2713aSLionel Sambuc char* (*fc)(char) = L('a');
86f4a2713aSLionel Sambuc fc('b');
87f4a2713aSLionel Sambuc L('c');
88f4a2713aSLionel Sambuc double* (*fd)(double) = L(3.14);
89f4a2713aSLionel Sambuc fd(3.14);
90f4a2713aSLionel Sambuc fd(6.26);
91f4a2713aSLionel Sambuc }
92f4a2713aSLionel Sambuc {
93f4a2713aSLionel Sambuc auto L = [=](auto b) {
94f4a2713aSLionel Sambuc return [](auto a) ->decltype(b)* { return (decltype(b)*)0; }; //expected-note{{candidate template ignored}}
95f4a2713aSLionel Sambuc };
96f4a2713aSLionel Sambuc char* (*fp)(int) = L('8');
97f4a2713aSLionel Sambuc fp(5);
98f4a2713aSLionel Sambuc char* (*fc)(char) = L('a');
99f4a2713aSLionel Sambuc fc('b');
100f4a2713aSLionel Sambuc double* (*fi)(int) = L(3.14);
101f4a2713aSLionel Sambuc fi(5);
102f4a2713aSLionel Sambuc int* (*fi2)(int) = L(3.14); //expected-error{{no viable conversion}}
103f4a2713aSLionel Sambuc }
104f4a2713aSLionel Sambuc
105f4a2713aSLionel Sambuc {
106f4a2713aSLionel Sambuc auto L = [=](auto b) {
107f4a2713aSLionel Sambuc return [](auto a) {
108f4a2713aSLionel Sambuc return [=](auto c) {
109f4a2713aSLionel Sambuc return [](auto d) ->decltype(a + b + c + d) { return d; };
110f4a2713aSLionel Sambuc };
111f4a2713aSLionel Sambuc };
112f4a2713aSLionel Sambuc };
113f4a2713aSLionel Sambuc int (*fp)(int) = L('8')(3)(short{});
114f4a2713aSLionel Sambuc double (*fs)(char) = L(3.14)(short{})('4');
115f4a2713aSLionel Sambuc }
116f4a2713aSLionel Sambuc
117f4a2713aSLionel Sambuc fooT(3);
118f4a2713aSLionel Sambuc fooT('a');
119f4a2713aSLionel Sambuc fooT(3.14);
120f4a2713aSLionel Sambuc fooT("abcdefg");
121f4a2713aSLionel Sambuc return 0;
122f4a2713aSLionel Sambuc }
123f4a2713aSLionel Sambuc int run2 = test();
124f4a2713aSLionel Sambuc
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc
127f4a2713aSLionel Sambuc
128f4a2713aSLionel Sambuc namespace test_conversion_to_fptr {
129f4a2713aSLionel Sambuc
f1(int (*)(int))130f4a2713aSLionel Sambuc void f1(int (*)(int)) { }
f2(char (*)(int))131f4a2713aSLionel Sambuc void f2(char (*)(int)) { } // expected-note{{candidate}}
g(int (*)(int))132f4a2713aSLionel Sambuc void g(int (*)(int)) { } // #1 expected-note{{candidate}}
g(char (*)(char))133f4a2713aSLionel Sambuc void g(char (*)(char)) { } // #2 expected-note{{candidate}}
h(int (*)(int))134f4a2713aSLionel Sambuc void h(int (*)(int)) { } // #3
h(char (*)(int))135f4a2713aSLionel Sambuc void h(char (*)(int)) { } // #4
136f4a2713aSLionel Sambuc
test()137f4a2713aSLionel Sambuc int test() {
138f4a2713aSLionel Sambuc {
139f4a2713aSLionel Sambuc auto glambda = [](auto a) { return a; };
140f4a2713aSLionel Sambuc glambda(1);
141f4a2713aSLionel Sambuc f1(glambda); // OK
142f4a2713aSLionel Sambuc f2(glambda); // expected-error{{no matching function}}
143f4a2713aSLionel Sambuc g(glambda); // expected-error{{call to 'g' is ambiguous}}
144f4a2713aSLionel Sambuc h(glambda); // OK: calls #3 since it is convertible from ID
145f4a2713aSLionel Sambuc
146f4a2713aSLionel Sambuc int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
147f4a2713aSLionel Sambuc
148f4a2713aSLionel Sambuc }
149f4a2713aSLionel Sambuc {
150f4a2713aSLionel Sambuc
151f4a2713aSLionel Sambuc auto L = [](auto a) { return a; };
152f4a2713aSLionel Sambuc int (*fp)(int) = L;
153f4a2713aSLionel Sambuc fp(5);
154f4a2713aSLionel Sambuc L(3);
155f4a2713aSLionel Sambuc char (*fc)(char) = L;
156f4a2713aSLionel Sambuc fc('b');
157f4a2713aSLionel Sambuc L('c');
158f4a2713aSLionel Sambuc double (*fd)(double) = L;
159f4a2713aSLionel Sambuc fd(3.14);
160f4a2713aSLionel Sambuc fd(6.26);
161f4a2713aSLionel Sambuc L(4.25);
162f4a2713aSLionel Sambuc }
163f4a2713aSLionel Sambuc {
164f4a2713aSLionel Sambuc auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
165f4a2713aSLionel Sambuc int (*fp)(int) = L;
166f4a2713aSLionel Sambuc char (*fc)(char) = L; //expected-error{{no viable conversion}}
167f4a2713aSLionel Sambuc double (*fd)(double) = L; //expected-error{{no viable conversion}}
168f4a2713aSLionel Sambuc }
169f4a2713aSLionel Sambuc {
170f4a2713aSLionel Sambuc int* (*fp)(int*) = [](auto *a) -> auto* { return a; };
171f4a2713aSLionel Sambuc fp(0);
172f4a2713aSLionel Sambuc }
173f4a2713aSLionel Sambuc }
174f4a2713aSLionel Sambuc
175f4a2713aSLionel Sambuc namespace more_converion_to_ptr_to_function_tests {
176f4a2713aSLionel Sambuc
177f4a2713aSLionel Sambuc
test()178f4a2713aSLionel Sambuc int test() {
179f4a2713aSLionel Sambuc {
180f4a2713aSLionel Sambuc int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
181f4a2713aSLionel Sambuc int (*fp2)(int) = [](auto b) -> int { return b; };
182f4a2713aSLionel Sambuc int (*fp3)(char) = [](auto c) -> int { return c; };
183f4a2713aSLionel Sambuc char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
184f4a2713aSLionel Sambuc //expected-note{{candidate template ignored}}
185f4a2713aSLionel Sambuc char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
186f4a2713aSLionel Sambuc //expected-note{{candidate template ignored}}
187f4a2713aSLionel Sambuc
188f4a2713aSLionel Sambuc fp2(3);
189f4a2713aSLionel Sambuc fp3('\n');
190f4a2713aSLionel Sambuc fp3('a');
191f4a2713aSLionel Sambuc return 0;
192f4a2713aSLionel Sambuc }
193f4a2713aSLionel Sambuc } // end test()
194f4a2713aSLionel Sambuc
vfun(Ts...)195f4a2713aSLionel Sambuc template<class ... Ts> void vfun(Ts ... ) { }
196f4a2713aSLionel Sambuc
variadic_test()197f4a2713aSLionel Sambuc int variadic_test() {
198f4a2713aSLionel Sambuc
199f4a2713aSLionel Sambuc int (*fp)(int, char, double) = [](auto ... a) -> int { vfun(a...); return 4; };
200f4a2713aSLionel Sambuc fp(3, '4', 3.14);
201f4a2713aSLionel Sambuc
202f4a2713aSLionel Sambuc int (*fp2)(int, char, double) = [](auto ... a) { vfun(a...); return 4; };
203f4a2713aSLionel Sambuc fp(3, '4', 3.14);
204f4a2713aSLionel Sambuc return 2;
205f4a2713aSLionel Sambuc }
206f4a2713aSLionel Sambuc
207f4a2713aSLionel Sambuc } // end ns
208f4a2713aSLionel Sambuc
209f4a2713aSLionel Sambuc namespace conversion_operator {
test()210f4a2713aSLionel Sambuc void test() {
211f4a2713aSLionel Sambuc auto L = [](auto a) -> int { return a; };
212f4a2713aSLionel Sambuc int (*fp)(int) = L;
213f4a2713aSLionel Sambuc int (&fp2)(int) = [](auto a) { return a; }; // expected-error{{non-const lvalue}}
214f4a2713aSLionel Sambuc int (&&fp3)(int) = [](auto a) { return a; }; // expected-error{{no viable conversion}}\
215f4a2713aSLionel Sambuc //expected-note{{candidate}}
216f4a2713aSLionel Sambuc }
217f4a2713aSLionel Sambuc }
218f4a2713aSLionel Sambuc }
219f4a2713aSLionel Sambuc
220f4a2713aSLionel Sambuc namespace return_type_deduction_ok {
__anon001ec7461e02(auto a) 221f4a2713aSLionel Sambuc auto l = [](auto a) ->auto { return a; }(2);
222f4a2713aSLionel Sambuc auto l2 = [](auto a) ->decltype(auto) { return a; }(2);
__anon001ec7461f02(auto a) 223f4a2713aSLionel Sambuc auto l3 = [](auto a) { return a; }(2);
224f4a2713aSLionel Sambuc
225f4a2713aSLionel Sambuc }
226f4a2713aSLionel Sambuc
227f4a2713aSLionel Sambuc namespace generic_lambda_as_default_argument_ok {
__anon001ec7462002(auto a)228f4a2713aSLionel Sambuc void test(int i = [](auto a)->int { return a; }(3)) {
229f4a2713aSLionel Sambuc }
230f4a2713aSLionel Sambuc }
231f4a2713aSLionel Sambuc
232f4a2713aSLionel Sambuc namespace nested_non_capturing_lambda_tests {
print(Ts...)233f4a2713aSLionel Sambuc template<class ... Ts> void print(Ts ...) { }
test()234f4a2713aSLionel Sambuc int test() {
235f4a2713aSLionel Sambuc {
236f4a2713aSLionel Sambuc auto L = [](auto a) {
237f4a2713aSLionel Sambuc return [](auto b) {
238f4a2713aSLionel Sambuc return b;
239f4a2713aSLionel Sambuc };
240f4a2713aSLionel Sambuc };
241f4a2713aSLionel Sambuc auto M = L(3);
242f4a2713aSLionel Sambuc M(4.15);
243f4a2713aSLionel Sambuc }
244f4a2713aSLionel Sambuc {
245f4a2713aSLionel Sambuc int i = 10; //expected-note 3{{declared here}}
246f4a2713aSLionel Sambuc auto L = [](auto a) {
247f4a2713aSLionel Sambuc return [](auto b) { //expected-note 3{{begins here}}
248f4a2713aSLionel Sambuc i = b; //expected-error 3{{cannot be implicitly captured}}
249f4a2713aSLionel Sambuc return b;
250f4a2713aSLionel Sambuc };
251f4a2713aSLionel Sambuc };
252f4a2713aSLionel Sambuc auto M = L(3); //expected-note{{instantiation}}
253f4a2713aSLionel Sambuc M(4.15); //expected-note{{instantiation}}
254f4a2713aSLionel Sambuc }
255f4a2713aSLionel Sambuc {
256f4a2713aSLionel Sambuc int i = 10;
257f4a2713aSLionel Sambuc auto L = [](auto a) {
258f4a2713aSLionel Sambuc return [](auto b) {
259f4a2713aSLionel Sambuc b = sizeof(i); //ok
260f4a2713aSLionel Sambuc return b;
261f4a2713aSLionel Sambuc };
262f4a2713aSLionel Sambuc };
263f4a2713aSLionel Sambuc }
264f4a2713aSLionel Sambuc {
265f4a2713aSLionel Sambuc auto L = [](auto a) {
266f4a2713aSLionel Sambuc print("a = ", a, "\n");
267f4a2713aSLionel Sambuc return [](auto b) ->decltype(a) {
268f4a2713aSLionel Sambuc print("b = ", b, "\n");
269f4a2713aSLionel Sambuc return b;
270f4a2713aSLionel Sambuc };
271f4a2713aSLionel Sambuc };
272f4a2713aSLionel Sambuc auto M = L(3);
273f4a2713aSLionel Sambuc M(4.15);
274f4a2713aSLionel Sambuc }
275f4a2713aSLionel Sambuc
276f4a2713aSLionel Sambuc {
277f4a2713aSLionel Sambuc auto L = [](auto a) ->decltype(a) {
278f4a2713aSLionel Sambuc print("a = ", a, "\n");
279f4a2713aSLionel Sambuc return [](auto b) ->decltype(a) { //expected-error{{no viable conversion}}\
280f4a2713aSLionel Sambuc //expected-note{{candidate template ignored}}
281f4a2713aSLionel Sambuc print("b = ", b, "\n");
282f4a2713aSLionel Sambuc return b;
283f4a2713aSLionel Sambuc };
284f4a2713aSLionel Sambuc };
285f4a2713aSLionel Sambuc auto M = L(3); //expected-note{{in instantiation of}}
286f4a2713aSLionel Sambuc }
287f4a2713aSLionel Sambuc {
288f4a2713aSLionel Sambuc auto L = [](auto a) {
289f4a2713aSLionel Sambuc print("a = ", a, "\n");
290f4a2713aSLionel Sambuc return [](auto ... b) ->decltype(a) {
291f4a2713aSLionel Sambuc print("b = ", b ..., "\n");
292f4a2713aSLionel Sambuc return 4;
293f4a2713aSLionel Sambuc };
294f4a2713aSLionel Sambuc };
295f4a2713aSLionel Sambuc auto M = L(3);
296f4a2713aSLionel Sambuc M(4.15, 3, "fv");
297f4a2713aSLionel Sambuc }
298f4a2713aSLionel Sambuc
299f4a2713aSLionel Sambuc {
300f4a2713aSLionel Sambuc auto L = [](auto a) {
301f4a2713aSLionel Sambuc print("a = ", a, "\n");
302f4a2713aSLionel Sambuc return [](auto ... b) ->decltype(a) {
303f4a2713aSLionel Sambuc print("b = ", b ..., "\n");
304f4a2713aSLionel Sambuc return 4;
305f4a2713aSLionel Sambuc };
306f4a2713aSLionel Sambuc };
307f4a2713aSLionel Sambuc auto M = L(3);
308f4a2713aSLionel Sambuc int (*fp)(double, int, const char*) = M;
309f4a2713aSLionel Sambuc fp(4.15, 3, "fv");
310f4a2713aSLionel Sambuc }
311f4a2713aSLionel Sambuc
312f4a2713aSLionel Sambuc {
313f4a2713aSLionel Sambuc auto L = [](auto a) {
314f4a2713aSLionel Sambuc print("a = ", a, "\n");
315f4a2713aSLionel Sambuc return [](char b) {
316f4a2713aSLionel Sambuc return [](auto ... c) ->decltype(b) {
317f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
318f4a2713aSLionel Sambuc return 42;
319f4a2713aSLionel Sambuc };
320f4a2713aSLionel Sambuc };
321f4a2713aSLionel Sambuc };
322f4a2713aSLionel Sambuc L(4);
323f4a2713aSLionel Sambuc auto M = L(3);
324f4a2713aSLionel Sambuc M('a');
325f4a2713aSLionel Sambuc auto N = M('x');
326f4a2713aSLionel Sambuc N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
327f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = N;
328f4a2713aSLionel Sambuc np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
329f4a2713aSLionel Sambuc }
330f4a2713aSLionel Sambuc
331f4a2713aSLionel Sambuc
332f4a2713aSLionel Sambuc {
333f4a2713aSLionel Sambuc auto L = [](auto a) {
334f4a2713aSLionel Sambuc print("a = ", a, "\n");
335f4a2713aSLionel Sambuc return [](decltype(a) b) {
336f4a2713aSLionel Sambuc return [](auto ... c) ->decltype(b) {
337f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
338f4a2713aSLionel Sambuc return 42;
339f4a2713aSLionel Sambuc };
340f4a2713aSLionel Sambuc };
341f4a2713aSLionel Sambuc };
342f4a2713aSLionel Sambuc L('4');
343f4a2713aSLionel Sambuc auto M = L('3');
344f4a2713aSLionel Sambuc M('a');
345f4a2713aSLionel Sambuc auto N = M('x');
346f4a2713aSLionel Sambuc N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
347f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = N;
348f4a2713aSLionel Sambuc np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
349f4a2713aSLionel Sambuc }
350f4a2713aSLionel Sambuc
351f4a2713aSLionel Sambuc
352f4a2713aSLionel Sambuc {
353f4a2713aSLionel Sambuc struct X {
354f4a2713aSLionel Sambuc static void foo(double d) { }
355f4a2713aSLionel Sambuc void test() {
356f4a2713aSLionel Sambuc auto L = [](auto a) {
357f4a2713aSLionel Sambuc print("a = ", a, "\n");
358f4a2713aSLionel Sambuc foo(a);
359f4a2713aSLionel Sambuc return [](decltype(a) b) {
360f4a2713aSLionel Sambuc foo(b);
361f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
362f4a2713aSLionel Sambuc return [](auto ... c) ->decltype(b) {
363f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
364f4a2713aSLionel Sambuc foo(decltype(b){});
365f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
366f4a2713aSLionel Sambuc return 42;
367f4a2713aSLionel Sambuc };
368f4a2713aSLionel Sambuc };
369f4a2713aSLionel Sambuc };
370f4a2713aSLionel Sambuc L('4');
371f4a2713aSLionel Sambuc auto M = L('3');
372f4a2713aSLionel Sambuc M('a');
373f4a2713aSLionel Sambuc auto N = M('x');
374f4a2713aSLionel Sambuc N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
375f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = N;
376f4a2713aSLionel Sambuc np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
377f4a2713aSLionel Sambuc }
378f4a2713aSLionel Sambuc };
379f4a2713aSLionel Sambuc X x;
380f4a2713aSLionel Sambuc x.test();
381f4a2713aSLionel Sambuc }
382f4a2713aSLionel Sambuc // Make sure we can escape the function
383f4a2713aSLionel Sambuc {
384f4a2713aSLionel Sambuc struct X {
385f4a2713aSLionel Sambuc static void foo(double d) { }
386f4a2713aSLionel Sambuc auto test() {
387f4a2713aSLionel Sambuc auto L = [](auto a) {
388f4a2713aSLionel Sambuc print("a = ", a, "\n");
389f4a2713aSLionel Sambuc foo(a);
390f4a2713aSLionel Sambuc return [](decltype(a) b) {
391f4a2713aSLionel Sambuc foo(b);
392f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
393f4a2713aSLionel Sambuc return [](auto ... c) ->decltype(b) {
394f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
395f4a2713aSLionel Sambuc foo(decltype(b){});
396f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
397f4a2713aSLionel Sambuc return 42;
398f4a2713aSLionel Sambuc };
399f4a2713aSLionel Sambuc };
400f4a2713aSLionel Sambuc };
401f4a2713aSLionel Sambuc return L;
402f4a2713aSLionel Sambuc }
403f4a2713aSLionel Sambuc };
404f4a2713aSLionel Sambuc X x;
405f4a2713aSLionel Sambuc auto L = x.test();
406f4a2713aSLionel Sambuc L('4');
407f4a2713aSLionel Sambuc auto M = L('3');
408f4a2713aSLionel Sambuc M('a');
409f4a2713aSLionel Sambuc auto N = M('x');
410f4a2713aSLionel Sambuc N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
411f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = N;
412f4a2713aSLionel Sambuc np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
413f4a2713aSLionel Sambuc }
414f4a2713aSLionel Sambuc
415f4a2713aSLionel Sambuc {
416f4a2713aSLionel Sambuc struct X {
417f4a2713aSLionel Sambuc static void foo(double d) { }
418f4a2713aSLionel Sambuc auto test() {
419f4a2713aSLionel Sambuc auto L = [](auto a) {
420f4a2713aSLionel Sambuc print("a = ", a, "\n");
421f4a2713aSLionel Sambuc foo(a);
422f4a2713aSLionel Sambuc return [](decltype(a) b) {
423f4a2713aSLionel Sambuc foo(b);
424f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
425f4a2713aSLionel Sambuc return [](auto ... c) {
426f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
427f4a2713aSLionel Sambuc foo(decltype(b){});
428f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
429f4a2713aSLionel Sambuc return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
430f4a2713aSLionel Sambuc print("d = ", d ..., "\n");
431f4a2713aSLionel Sambuc foo(decltype(b){});
432f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
433f4a2713aSLionel Sambuc return decltype(a){};
434f4a2713aSLionel Sambuc };
435f4a2713aSLionel Sambuc };
436f4a2713aSLionel Sambuc };
437f4a2713aSLionel Sambuc };
438f4a2713aSLionel Sambuc return L;
439f4a2713aSLionel Sambuc }
440f4a2713aSLionel Sambuc };
441f4a2713aSLionel Sambuc X x;
442f4a2713aSLionel Sambuc auto L = x.test();
443f4a2713aSLionel Sambuc L('4');
444f4a2713aSLionel Sambuc auto M = L('3');
445f4a2713aSLionel Sambuc M('a');
446f4a2713aSLionel Sambuc auto N = M('x');
447f4a2713aSLionel Sambuc auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
448f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = O;
449f4a2713aSLionel Sambuc np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
450f4a2713aSLionel Sambuc int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
451f4a2713aSLionel Sambuc
452f4a2713aSLionel Sambuc }
453f4a2713aSLionel Sambuc } // end test()
454f4a2713aSLionel Sambuc
455f4a2713aSLionel Sambuc namespace wrapped_within_templates {
456f4a2713aSLionel Sambuc
457f4a2713aSLionel Sambuc namespace explicit_return {
fooT(T t)458f4a2713aSLionel Sambuc template<class T> int fooT(T t) {
459f4a2713aSLionel Sambuc auto L = [](auto a) -> void {
460f4a2713aSLionel Sambuc auto M = [](char b) -> void {
461f4a2713aSLionel Sambuc auto N = [](auto c) -> void {
462f4a2713aSLionel Sambuc int x = 0;
463f4a2713aSLionel Sambuc x = sizeof(a);
464f4a2713aSLionel Sambuc x = sizeof(b);
465f4a2713aSLionel Sambuc x = sizeof(c);
466f4a2713aSLionel Sambuc };
467f4a2713aSLionel Sambuc N('a');
468f4a2713aSLionel Sambuc N(decltype(a){});
469f4a2713aSLionel Sambuc };
470f4a2713aSLionel Sambuc };
471f4a2713aSLionel Sambuc L(t);
472f4a2713aSLionel Sambuc L(3.14);
473f4a2713aSLionel Sambuc return 0;
474f4a2713aSLionel Sambuc }
475f4a2713aSLionel Sambuc
476f4a2713aSLionel Sambuc int run = fooT('a') + fooT(3.14);
477f4a2713aSLionel Sambuc
478f4a2713aSLionel Sambuc } // end explicit_return
479f4a2713aSLionel Sambuc
480f4a2713aSLionel Sambuc namespace implicit_return_deduction {
fooT(T t)481f4a2713aSLionel Sambuc template<class T> auto fooT(T t) {
482f4a2713aSLionel Sambuc auto L = [](auto a) {
483f4a2713aSLionel Sambuc auto M = [](char b) {
484f4a2713aSLionel Sambuc auto N = [](auto c) {
485f4a2713aSLionel Sambuc int x = 0;
486f4a2713aSLionel Sambuc x = sizeof(a);
487f4a2713aSLionel Sambuc x = sizeof(b);
488f4a2713aSLionel Sambuc x = sizeof(c);
489f4a2713aSLionel Sambuc };
490f4a2713aSLionel Sambuc N('a');
491f4a2713aSLionel Sambuc N(decltype(a){});
492f4a2713aSLionel Sambuc };
493f4a2713aSLionel Sambuc };
494f4a2713aSLionel Sambuc L(t);
495f4a2713aSLionel Sambuc L(3.14);
496f4a2713aSLionel Sambuc return 0;
497f4a2713aSLionel Sambuc }
498f4a2713aSLionel Sambuc
499f4a2713aSLionel Sambuc int run = fooT('a') + fooT(3.14);
500f4a2713aSLionel Sambuc
print(Ts...ts)501f4a2713aSLionel Sambuc template<class ... Ts> void print(Ts ... ts) { }
502f4a2713aSLionel Sambuc
fooV(Ts...ts)503f4a2713aSLionel Sambuc template<class ... Ts> auto fooV(Ts ... ts) {
504f4a2713aSLionel Sambuc auto L = [](auto ... a) {
505f4a2713aSLionel Sambuc auto M = [](decltype(a) ... b) {
506f4a2713aSLionel Sambuc auto N = [](auto c) {
507f4a2713aSLionel Sambuc int x = 0;
508f4a2713aSLionel Sambuc x = sizeof...(a);
509f4a2713aSLionel Sambuc x = sizeof...(b);
510f4a2713aSLionel Sambuc x = sizeof(c);
511f4a2713aSLionel Sambuc };
512f4a2713aSLionel Sambuc N('a');
513f4a2713aSLionel Sambuc N(N);
514f4a2713aSLionel Sambuc N(first<Ts...>{});
515f4a2713aSLionel Sambuc };
516f4a2713aSLionel Sambuc M(a...);
517f4a2713aSLionel Sambuc print("a = ", a..., "\n");
518f4a2713aSLionel Sambuc };
519f4a2713aSLionel Sambuc L(L, ts...);
520f4a2713aSLionel Sambuc print("ts = ", ts..., "\n");
521f4a2713aSLionel Sambuc return 0;
522f4a2713aSLionel Sambuc }
523f4a2713aSLionel Sambuc
524f4a2713aSLionel Sambuc int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
525f4a2713aSLionel Sambuc
526f4a2713aSLionel Sambuc } //implicit_return_deduction
527f4a2713aSLionel Sambuc
528f4a2713aSLionel Sambuc
529f4a2713aSLionel Sambuc } //wrapped_within_templates
530f4a2713aSLionel Sambuc
531f4a2713aSLionel Sambuc namespace at_ns_scope {
foo(double d)532f4a2713aSLionel Sambuc void foo(double d) { }
test()533f4a2713aSLionel Sambuc auto test() {
534f4a2713aSLionel Sambuc auto L = [](auto a) {
535f4a2713aSLionel Sambuc print("a = ", a, "\n");
536f4a2713aSLionel Sambuc foo(a);
537f4a2713aSLionel Sambuc return [](decltype(a) b) {
538f4a2713aSLionel Sambuc foo(b);
539f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
540f4a2713aSLionel Sambuc return [](auto ... c) {
541f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
542f4a2713aSLionel Sambuc foo(decltype(b){});
543f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
544f4a2713aSLionel Sambuc return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
545f4a2713aSLionel Sambuc print("d = ", d ..., "\n");
546f4a2713aSLionel Sambuc foo(decltype(b){});
547f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
548f4a2713aSLionel Sambuc return decltype(a){};
549f4a2713aSLionel Sambuc };
550f4a2713aSLionel Sambuc };
551f4a2713aSLionel Sambuc };
552f4a2713aSLionel Sambuc };
553f4a2713aSLionel Sambuc return L;
554f4a2713aSLionel Sambuc }
555f4a2713aSLionel Sambuc auto L = test();
556f4a2713aSLionel Sambuc auto L_test = L('4');
557f4a2713aSLionel Sambuc auto M = L('3');
558f4a2713aSLionel Sambuc auto M_test = M('a');
559f4a2713aSLionel Sambuc auto N = M('x');
560f4a2713aSLionel Sambuc auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
561f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = O;
562f4a2713aSLionel Sambuc auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
563f4a2713aSLionel Sambuc int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
564f4a2713aSLionel Sambuc
565f4a2713aSLionel Sambuc
566f4a2713aSLionel Sambuc
567f4a2713aSLionel Sambuc }
568f4a2713aSLionel Sambuc
569f4a2713aSLionel Sambuc namespace variadic_tests_1 {
print(Ts...ts)570f4a2713aSLionel Sambuc template<class ... Ts> void print(Ts ... ts) { }
571f4a2713aSLionel Sambuc
FirstArg(F & f,Rest...)572f4a2713aSLionel Sambuc template<class F, class ... Rest> F& FirstArg(F& f, Rest...) { return f; }
573f4a2713aSLionel Sambuc
fooV(Ts...ts)574f4a2713aSLionel Sambuc template<class ... Ts> int fooV(Ts ... ts) {
575f4a2713aSLionel Sambuc auto L = [](auto ... a) -> void {
576f4a2713aSLionel Sambuc auto M = [](decltype(a) ... b) -> void {
577f4a2713aSLionel Sambuc auto N = [](auto c) -> void {
578f4a2713aSLionel Sambuc int x = 0;
579f4a2713aSLionel Sambuc x = sizeof...(a);
580f4a2713aSLionel Sambuc x = sizeof...(b);
581f4a2713aSLionel Sambuc x = sizeof(c);
582f4a2713aSLionel Sambuc };
583f4a2713aSLionel Sambuc N('a');
584f4a2713aSLionel Sambuc N(N);
585*0a6a1f1dSLionel Sambuc N(first<Ts...>{});
586f4a2713aSLionel Sambuc };
587f4a2713aSLionel Sambuc M(a...);
588f4a2713aSLionel Sambuc print("a = ", a..., "\n");
589f4a2713aSLionel Sambuc };
590f4a2713aSLionel Sambuc L(L, ts...);
591f4a2713aSLionel Sambuc print("ts = ", ts..., "\n");
592f4a2713aSLionel Sambuc return 0;
593f4a2713aSLionel Sambuc }
594f4a2713aSLionel Sambuc
595f4a2713aSLionel Sambuc int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
596f4a2713aSLionel Sambuc
597f4a2713aSLionel Sambuc namespace more_variadic_1 {
598f4a2713aSLionel Sambuc
fooV(Ts...ts)599f4a2713aSLionel Sambuc template<class ... Ts> int fooV(Ts ... ts) {
600f4a2713aSLionel Sambuc auto L = [](auto ... a) {
601f4a2713aSLionel Sambuc auto M = [](decltype(a) ... b) -> void {
602f4a2713aSLionel Sambuc auto N = [](auto c) -> void {
603f4a2713aSLionel Sambuc int x = 0;
604f4a2713aSLionel Sambuc x = sizeof...(a);
605f4a2713aSLionel Sambuc x = sizeof...(b);
606f4a2713aSLionel Sambuc x = sizeof(c);
607f4a2713aSLionel Sambuc };
608f4a2713aSLionel Sambuc N('a');
609f4a2713aSLionel Sambuc N(N);
610*0a6a1f1dSLionel Sambuc N(first<Ts...>{});
611f4a2713aSLionel Sambuc };
612f4a2713aSLionel Sambuc M(a...);
613f4a2713aSLionel Sambuc return M;
614f4a2713aSLionel Sambuc };
615f4a2713aSLionel Sambuc auto M = L(L, ts...);
616f4a2713aSLionel Sambuc decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
617f4a2713aSLionel Sambuc void (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
618f4a2713aSLionel Sambuc
619f4a2713aSLionel Sambuc {
620f4a2713aSLionel Sambuc auto L = [](auto ... a) {
621f4a2713aSLionel Sambuc auto M = [](decltype(a) ... b) {
622f4a2713aSLionel Sambuc auto N = [](auto c) -> void {
623f4a2713aSLionel Sambuc int x = 0;
624f4a2713aSLionel Sambuc x = sizeof...(a);
625f4a2713aSLionel Sambuc x = sizeof...(b);
626f4a2713aSLionel Sambuc x = sizeof(c);
627f4a2713aSLionel Sambuc };
628f4a2713aSLionel Sambuc N('a');
629f4a2713aSLionel Sambuc N(N);
630*0a6a1f1dSLionel Sambuc N(first<Ts...>{});
631f4a2713aSLionel Sambuc return N;
632f4a2713aSLionel Sambuc };
633f4a2713aSLionel Sambuc M(a...);
634f4a2713aSLionel Sambuc return M;
635f4a2713aSLionel Sambuc };
636f4a2713aSLionel Sambuc auto M = L(L, ts...);
637f4a2713aSLionel Sambuc decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
638f4a2713aSLionel Sambuc fp(L, ts...);
639f4a2713aSLionel Sambuc decltype(L(L, ts...)(L, ts...)) (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
640f4a2713aSLionel Sambuc fp2 = fp(L, ts...);
641f4a2713aSLionel Sambuc void (*fp3)(char) = fp2(L, ts...);
642f4a2713aSLionel Sambuc fp3('a');
643f4a2713aSLionel Sambuc }
644f4a2713aSLionel Sambuc return 0;
645f4a2713aSLionel Sambuc }
646f4a2713aSLionel Sambuc
647f4a2713aSLionel Sambuc int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
648f4a2713aSLionel Sambuc
649f4a2713aSLionel Sambuc
650f4a2713aSLionel Sambuc } //end ns more_variadic_1
651f4a2713aSLionel Sambuc
652f4a2713aSLionel Sambuc } // end ns variadic_tests_1
653f4a2713aSLionel Sambuc
654f4a2713aSLionel Sambuc namespace at_ns_scope_within_class_member {
655f4a2713aSLionel Sambuc struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X656f4a2713aSLionel Sambuc static void foo(double d) { }
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X657f4a2713aSLionel Sambuc auto test() {
658f4a2713aSLionel Sambuc auto L = [](auto a) {
659f4a2713aSLionel Sambuc print("a = ", a, "\n");
660f4a2713aSLionel Sambuc foo(a);
661f4a2713aSLionel Sambuc return [](decltype(a) b) {
662f4a2713aSLionel Sambuc foo(b);
663f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
664f4a2713aSLionel Sambuc return [](auto ... c) {
665f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
666f4a2713aSLionel Sambuc foo(decltype(b){});
667f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
668f4a2713aSLionel Sambuc return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
669f4a2713aSLionel Sambuc print("d = ", d ..., "\n");
670f4a2713aSLionel Sambuc foo(decltype(b){});
671f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
672f4a2713aSLionel Sambuc return decltype(a){};
673f4a2713aSLionel Sambuc };
674f4a2713aSLionel Sambuc };
675f4a2713aSLionel Sambuc };
676f4a2713aSLionel Sambuc };
677f4a2713aSLionel Sambuc return L;
678f4a2713aSLionel Sambuc }
679f4a2713aSLionel Sambuc };
680f4a2713aSLionel Sambuc X x;
681f4a2713aSLionel Sambuc auto L = x.test();
682f4a2713aSLionel Sambuc auto L_test = L('4');
683f4a2713aSLionel Sambuc auto M = L('3');
684f4a2713aSLionel Sambuc auto M_test = M('a');
685f4a2713aSLionel Sambuc auto N = M('x');
686f4a2713aSLionel Sambuc auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
687f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = O;
688f4a2713aSLionel Sambuc auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
689f4a2713aSLionel Sambuc int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
690f4a2713aSLionel Sambuc
691f4a2713aSLionel Sambuc } //end at_ns_scope_within_class_member
692f4a2713aSLionel Sambuc
693f4a2713aSLionel Sambuc
694f4a2713aSLionel Sambuc namespace at_ns_scope_within_class_template_member {
695f4a2713aSLionel Sambuc struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X696f4a2713aSLionel Sambuc static void foo(double d) { }
697f4a2713aSLionel Sambuc template<class T = int>
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X698f4a2713aSLionel Sambuc auto test(T = T{}) {
__anon001ec7464d02(auto a) 699f4a2713aSLionel Sambuc auto L = [](auto a) {
700f4a2713aSLionel Sambuc print("a = ", a, "\n");
701f4a2713aSLionel Sambuc foo(a);
702f4a2713aSLionel Sambuc return [](decltype(a) b) {
703f4a2713aSLionel Sambuc foo(b);
704f4a2713aSLionel Sambuc foo(sizeof(a) + sizeof(b));
705f4a2713aSLionel Sambuc return [](auto ... c) {
706f4a2713aSLionel Sambuc print("c = ", c ..., "\n");
707f4a2713aSLionel Sambuc foo(decltype(b){});
708f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
709f4a2713aSLionel Sambuc return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
710f4a2713aSLionel Sambuc print("d = ", d ..., "\n");
711f4a2713aSLionel Sambuc foo(decltype(b){});
712f4a2713aSLionel Sambuc foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
713f4a2713aSLionel Sambuc return decltype(a){};
714f4a2713aSLionel Sambuc };
715f4a2713aSLionel Sambuc };
716f4a2713aSLionel Sambuc };
717f4a2713aSLionel Sambuc };
718f4a2713aSLionel Sambuc return L;
719f4a2713aSLionel Sambuc }
720f4a2713aSLionel Sambuc
721f4a2713aSLionel Sambuc };
722f4a2713aSLionel Sambuc X x;
723f4a2713aSLionel Sambuc auto L = x.test();
724f4a2713aSLionel Sambuc auto L_test = L('4');
725f4a2713aSLionel Sambuc auto M = L('3');
726f4a2713aSLionel Sambuc auto M_test = M('a');
727f4a2713aSLionel Sambuc auto N = M('x');
728f4a2713aSLionel Sambuc auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
729f4a2713aSLionel Sambuc char (*np)(const char*, int, const char*, double, const char*, int) = O;
730f4a2713aSLionel Sambuc auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
731f4a2713aSLionel Sambuc int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
732f4a2713aSLionel Sambuc
733f4a2713aSLionel Sambuc } //end at_ns_scope_within_class_member
734f4a2713aSLionel Sambuc
735f4a2713aSLionel Sambuc
736f4a2713aSLionel Sambuc namespace nested_generic_lambdas_123 {
test()737f4a2713aSLionel Sambuc void test() {
738f4a2713aSLionel Sambuc auto L = [](auto a) -> int {
739f4a2713aSLionel Sambuc auto M = [](auto b, decltype(a) b2) -> int {
740f4a2713aSLionel Sambuc return 1;
741f4a2713aSLionel Sambuc };
742f4a2713aSLionel Sambuc M(a, a);
743f4a2713aSLionel Sambuc };
744f4a2713aSLionel Sambuc L(3);
745f4a2713aSLionel Sambuc }
foo(T)746f4a2713aSLionel Sambuc template<class T> void foo(T) {
747f4a2713aSLionel Sambuc auto L = [](auto a) { return a; };
748f4a2713aSLionel Sambuc }
749f4a2713aSLionel Sambuc template void foo(int);
750f4a2713aSLionel Sambuc } // end ns nested_generic_lambdas_123
751f4a2713aSLionel Sambuc
752f4a2713aSLionel Sambuc namespace nested_fptr_235 {
test()753f4a2713aSLionel Sambuc int test()
754f4a2713aSLionel Sambuc {
755f4a2713aSLionel Sambuc auto L = [](auto b) {
756f4a2713aSLionel Sambuc return [](auto a) ->decltype(a) { return a; };
757f4a2713aSLionel Sambuc };
758f4a2713aSLionel Sambuc int (*fp)(int) = L(8);
759f4a2713aSLionel Sambuc fp(5);
760f4a2713aSLionel Sambuc L(3);
761f4a2713aSLionel Sambuc char (*fc)(char) = L('a');
762f4a2713aSLionel Sambuc fc('b');
763f4a2713aSLionel Sambuc L('c');
764f4a2713aSLionel Sambuc double (*fd)(double) = L(3.14);
765f4a2713aSLionel Sambuc fd(3.14);
766f4a2713aSLionel Sambuc fd(6.26);
767f4a2713aSLionel Sambuc return 0;
768f4a2713aSLionel Sambuc }
769f4a2713aSLionel Sambuc int run = test();
770f4a2713aSLionel Sambuc }
771f4a2713aSLionel Sambuc
772f4a2713aSLionel Sambuc
773f4a2713aSLionel Sambuc namespace fptr_with_decltype_return_type {
FirstArg(F & f,Rest &...r)774f4a2713aSLionel Sambuc template<class F, class ... Rest> F& FirstArg(F& f, Rest& ... r) { return f; };
vfun(Ts &&...ts)775f4a2713aSLionel Sambuc template<class ... Ts> auto vfun(Ts&& ... ts) {
776f4a2713aSLionel Sambuc print(ts...);
777f4a2713aSLionel Sambuc return FirstArg(ts...);
778f4a2713aSLionel Sambuc }
test()779f4a2713aSLionel Sambuc int test()
780f4a2713aSLionel Sambuc {
781f4a2713aSLionel Sambuc {
782f4a2713aSLionel Sambuc auto L = [](auto ... As) {
783f4a2713aSLionel Sambuc return [](auto b) ->decltype(b) {
784*0a6a1f1dSLionel Sambuc vfun([](decltype(As) a) -> decltype(a) { return a; } ...)(first<decltype(As)...>{});
785f4a2713aSLionel Sambuc return decltype(b){};
786f4a2713aSLionel Sambuc };
787f4a2713aSLionel Sambuc };
788f4a2713aSLionel Sambuc auto LL = L(1, 'a', 3.14, "abc");
789f4a2713aSLionel Sambuc LL("dim");
790f4a2713aSLionel Sambuc }
791f4a2713aSLionel Sambuc return 0;
792f4a2713aSLionel Sambuc }
793f4a2713aSLionel Sambuc int run = test();
794f4a2713aSLionel Sambuc }
795f4a2713aSLionel Sambuc
796f4a2713aSLionel Sambuc } // end ns nested_non_capturing_lambda_tests
797f4a2713aSLionel Sambuc
798f4a2713aSLionel Sambuc namespace PR17476 {
799f4a2713aSLionel Sambuc struct string {
stringPR17476::string800f4a2713aSLionel Sambuc string(const char *__s) { }
operator +=PR17476::string801f4a2713aSLionel Sambuc string &operator+=(const string &__str) { return *this; }
802f4a2713aSLionel Sambuc };
803f4a2713aSLionel Sambuc
804f4a2713aSLionel Sambuc template <class T>
finalizeDefaultAtomValues()805f4a2713aSLionel Sambuc void finalizeDefaultAtomValues() {
806f4a2713aSLionel Sambuc auto startEnd = [](const char * sym) -> void {
807f4a2713aSLionel Sambuc string start("__");
808f4a2713aSLionel Sambuc start += sym;
809f4a2713aSLionel Sambuc };
810f4a2713aSLionel Sambuc startEnd("preinit_array");
811f4a2713aSLionel Sambuc }
812f4a2713aSLionel Sambuc
f()813f4a2713aSLionel Sambuc void f() { finalizeDefaultAtomValues<char>(); }
814f4a2713aSLionel Sambuc
815f4a2713aSLionel Sambuc }
816f4a2713aSLionel Sambuc
817f4a2713aSLionel Sambuc namespace PR17476_variant {
818f4a2713aSLionel Sambuc struct string {
stringPR17476_variant::string819f4a2713aSLionel Sambuc string(const char *__s) { }
operator +=PR17476_variant::string820f4a2713aSLionel Sambuc string &operator+=(const string &__str) { return *this; }
821f4a2713aSLionel Sambuc };
822f4a2713aSLionel Sambuc
823f4a2713aSLionel Sambuc template <class T>
finalizeDefaultAtomValues()824f4a2713aSLionel Sambuc void finalizeDefaultAtomValues() {
825f4a2713aSLionel Sambuc auto startEnd = [](const T *sym) -> void {
826f4a2713aSLionel Sambuc string start("__");
827f4a2713aSLionel Sambuc start += sym;
828f4a2713aSLionel Sambuc };
829f4a2713aSLionel Sambuc startEnd("preinit_array");
830f4a2713aSLionel Sambuc }
831f4a2713aSLionel Sambuc
f()832f4a2713aSLionel Sambuc void f() { finalizeDefaultAtomValues<char>(); }
833f4a2713aSLionel Sambuc
834f4a2713aSLionel Sambuc }
835f4a2713aSLionel Sambuc
836f4a2713aSLionel Sambuc namespace PR17877_lambda_declcontext_and_get_cur_lambda_disconnect {
837f4a2713aSLionel Sambuc
838f4a2713aSLionel Sambuc
839f4a2713aSLionel Sambuc template<class T> struct U {
840f4a2713aSLionel Sambuc int t = 0;
841f4a2713aSLionel Sambuc };
842f4a2713aSLionel Sambuc
843f4a2713aSLionel Sambuc template<class T>
844f4a2713aSLionel Sambuc struct V {
sizePR17877_lambda_declcontext_and_get_cur_lambda_disconnect::V845f4a2713aSLionel Sambuc U<T> size() const { return U<T>{}; }
846f4a2713aSLionel Sambuc };
847f4a2713aSLionel Sambuc
848f4a2713aSLionel Sambuc template<typename T>
Do()849f4a2713aSLionel Sambuc void Do() {
850f4a2713aSLionel Sambuc V<int> v{};
851f4a2713aSLionel Sambuc [=] { v.size(); };
852f4a2713aSLionel Sambuc }
853f4a2713aSLionel Sambuc
854*0a6a1f1dSLionel Sambuc }
855f4a2713aSLionel Sambuc
856*0a6a1f1dSLionel Sambuc namespace inclass_lambdas_within_nested_classes {
857*0a6a1f1dSLionel Sambuc namespace ns1 {
858*0a6a1f1dSLionel Sambuc
859*0a6a1f1dSLionel Sambuc struct X1 {
860*0a6a1f1dSLionel Sambuc struct X2 {
__anon001ec7465902(auto i) 861*0a6a1f1dSLionel Sambuc enum { E = [](auto i) { return i; }(3) }; //expected-error{{inside of a constant expression}}\
862*0a6a1f1dSLionel Sambuc //expected-error{{not an integral constant}}\
863*0a6a1f1dSLionel Sambuc //expected-note{{non-literal type}}
__anon001ec7465a02inclass_lambdas_within_nested_classes::ns1::X1::X2864*0a6a1f1dSLionel Sambuc int L = ([] (int i) { return i; })(2);
fooinclass_lambdas_within_nested_classes::ns1::X1::X2865*0a6a1f1dSLionel Sambuc void foo(int i = ([] (int i) { return i; })(2)) { }
__anon001ec7465c02inclass_lambdas_within_nested_classes::ns1::X1::X2866*0a6a1f1dSLionel Sambuc int B : ([](int i) { return i; })(3); //expected-error{{inside of a constant expression}}\
867*0a6a1f1dSLionel Sambuc //expected-error{{not an integral constant}}\
868*0a6a1f1dSLionel Sambuc //expected-note{{non-literal type}}
__anon001ec7465d02inclass_lambdas_within_nested_classes::ns1::X1::X2869*0a6a1f1dSLionel Sambuc int arr[([](int i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
870*0a6a1f1dSLionel Sambuc //expected-error{{must have a constant size}}
__anon001ec7465e02inclass_lambdas_within_nested_classes::ns1::X1::X2871*0a6a1f1dSLionel Sambuc int (*fp)(int) = [](int i) { return i; };
__anon001ec7465f02inclass_lambdas_within_nested_classes::ns1::X1::X2872*0a6a1f1dSLionel Sambuc void fooptr(int (*fp)(char) = [](char c) { return 0; }) { }
__anon001ec7466002inclass_lambdas_within_nested_classes::ns1::X1::X2873*0a6a1f1dSLionel Sambuc int L2 = ([](auto i) { return i; })(2);
fooGinclass_lambdas_within_nested_classes::ns1::X1::X2874*0a6a1f1dSLionel Sambuc void fooG(int i = ([] (auto i) { return i; })(2)) { }
__anon001ec7466202inclass_lambdas_within_nested_classes::ns1::X1::X2875*0a6a1f1dSLionel Sambuc int BG : ([](auto i) { return i; })(3); //expected-error{{inside of a constant expression}} \
876*0a6a1f1dSLionel Sambuc //expected-error{{not an integral constant}}\
877*0a6a1f1dSLionel Sambuc //expected-note{{non-literal type}}
__anon001ec7466302inclass_lambdas_within_nested_classes::ns1::X1::X2878*0a6a1f1dSLionel Sambuc int arrG[([](auto i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
879*0a6a1f1dSLionel Sambuc //expected-error{{must have a constant size}}
__anon001ec7466402inclass_lambdas_within_nested_classes::ns1::X1::X2880*0a6a1f1dSLionel Sambuc int (*fpG)(int) = [](auto i) { return i; };
fooptrGinclass_lambdas_within_nested_classes::ns1::X1::X2881*0a6a1f1dSLionel Sambuc void fooptrG(int (*fp)(char) = [](auto c) { return 0; }) { }
882*0a6a1f1dSLionel Sambuc };
883*0a6a1f1dSLionel Sambuc };
884*0a6a1f1dSLionel Sambuc } //end ns
885*0a6a1f1dSLionel Sambuc
886*0a6a1f1dSLionel Sambuc namespace ns2 {
887*0a6a1f1dSLionel Sambuc struct X1 {
888*0a6a1f1dSLionel Sambuc template<class T>
889*0a6a1f1dSLionel Sambuc struct X2 {
__anon001ec7466602inclass_lambdas_within_nested_classes::ns2::X1::X2890*0a6a1f1dSLionel Sambuc int L = ([] (T i) { return i; })(2);
__anon001ec7466702inclass_lambdas_within_nested_classes::ns2::X1::X2891*0a6a1f1dSLionel Sambuc void foo(int i = ([] (int i) { return i; })(2)) { }
__anon001ec7466802inclass_lambdas_within_nested_classes::ns2::X1::X2892*0a6a1f1dSLionel Sambuc int B : ([](T i) { return i; })(3); //expected-error{{inside of a constant expression}}\
893*0a6a1f1dSLionel Sambuc //expected-error{{not an integral constant}}\
894*0a6a1f1dSLionel Sambuc //expected-note{{non-literal type}}
__anon001ec7466902inclass_lambdas_within_nested_classes::ns2::X1::X2895*0a6a1f1dSLionel Sambuc int arr[([](T i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
896*0a6a1f1dSLionel Sambuc //expected-error{{must have a constant size}}
__anon001ec7466a02inclass_lambdas_within_nested_classes::ns2::X1::X2897*0a6a1f1dSLionel Sambuc int (*fp)(T) = [](T i) { return i; };
fooptrinclass_lambdas_within_nested_classes::ns2::X1::X2898*0a6a1f1dSLionel Sambuc void fooptr(T (*fp)(char) = [](char c) { return 0; }) { }
__anon001ec7466c02inclass_lambdas_within_nested_classes::ns2::X1::X2899*0a6a1f1dSLionel Sambuc int L2 = ([](auto i) { return i; })(2);
fooGinclass_lambdas_within_nested_classes::ns2::X1::X2900*0a6a1f1dSLionel Sambuc void fooG(T i = ([] (auto i) { return i; })(2)) { }
__anon001ec7466e02inclass_lambdas_within_nested_classes::ns2::X1::X2901*0a6a1f1dSLionel Sambuc int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}\
902*0a6a1f1dSLionel Sambuc //expected-note{{non-literal type}}
__anon001ec7466f02inclass_lambdas_within_nested_classes::ns2::X1::X2903*0a6a1f1dSLionel Sambuc int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}}
__anon001ec7467002inclass_lambdas_within_nested_classes::ns2::X1::X2904*0a6a1f1dSLionel Sambuc int (*fpG)(T) = [](auto i) { return i; };
fooptrGinclass_lambdas_within_nested_classes::ns2::X1::X2905*0a6a1f1dSLionel Sambuc void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }
fooG2inclass_lambdas_within_nested_classes::ns2::X1::X2906*0a6a1f1dSLionel Sambuc template<class U = char> int fooG2(T (*fp)(U) = [](auto a) { return 0; }) { return 0; }
__anon001ec7467302inclass_lambdas_within_nested_classes::ns2::X1::X2907*0a6a1f1dSLionel Sambuc template<class U = char> int fooG3(T (*fp)(U) = [](auto a) { return 0; });
908*0a6a1f1dSLionel Sambuc };
909*0a6a1f1dSLionel Sambuc };
910*0a6a1f1dSLionel Sambuc template<class T>
911*0a6a1f1dSLionel Sambuc template<class U>
fooG3(T (* fp)(U))912*0a6a1f1dSLionel Sambuc int X1::X2<T>::fooG3(T (*fp)(U)) { return 0; }
913*0a6a1f1dSLionel Sambuc X1::X2<int> x2; //expected-note 3{{in instantiation of}}
914*0a6a1f1dSLionel Sambuc int run1 = x2.fooG2();
915*0a6a1f1dSLionel Sambuc int run2 = x2.fooG3();
916*0a6a1f1dSLionel Sambuc } // end ns
917*0a6a1f1dSLionel Sambuc
918*0a6a1f1dSLionel Sambuc
919*0a6a1f1dSLionel Sambuc
920*0a6a1f1dSLionel Sambuc } //end ns inclass_lambdas_within_nested_classes
921*0a6a1f1dSLionel Sambuc
922*0a6a1f1dSLionel Sambuc namespace pr21684_disambiguate_auto_followed_by_ellipsis_no_id {
__anon001ec7467402(auto ...) 923*0a6a1f1dSLionel Sambuc int a = [](auto ...) { return 0; }();
924*0a6a1f1dSLionel Sambuc }
925*0a6a1f1dSLionel Sambuc
926*0a6a1f1dSLionel Sambuc namespace PR22117 {
__anon001ec7467502(auto) 927*0a6a1f1dSLionel Sambuc int x = [](auto) {
928*0a6a1f1dSLionel Sambuc return [](auto... run_args) {
929*0a6a1f1dSLionel Sambuc using T = int(decltype(run_args)...);
930*0a6a1f1dSLionel Sambuc return 0;
931*0a6a1f1dSLionel Sambuc };
932*0a6a1f1dSLionel Sambuc }(0)(0);
933f4a2713aSLionel Sambuc }
934