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