1 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -emit-llvm-only %s
2 // 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
5
6 template<class F, class ...Rest> struct first_impl { typedef F type; };
7 template<class ...Args> using first = typename first_impl<Args...>::type;
8
9 namespace simple_explicit_capture {
test()10 void test() {
11 int i;
12 auto L = [i](auto a) { return i + a; };
13 L(3.14);
14 }
15 }
16
17 namespace explicit_call {
test()18 int test() {
19 auto L = [](auto a) { return a; };
20 L.operator()(3);
21 L.operator()<char>(3.14); //expected-warning{{implicit conversion}}
22 return 0;
23 }
24 } //end ns
25
26 namespace test_conversion_to_fptr_2 {
27
28 template<class T> struct X {
29
__anondcda5c7e0302test_conversion_to_fptr_2::X30 T (*fp)(T) = [](auto a) { return a; };
31
32 };
33
34 X<int> xi;
35
36 template<class T>
__anondcda5c7e0402(auto a) 37 void fooT(T t, T (*fp)(T) = [](auto a) { return a; }) {
38 fp(t);
39 }
40
test()41 int test() {
42 {
43 auto L = [](auto a) { return a; };
44 int (*fp)(int) = L;
45 fp(5);
46 L(3);
47 char (*fc)(char) = L;
48 fc('b');
49 L('c');
50 double (*fd)(double) = L;
51 fd(3.14);
52 fd(6.26);
53 L(4.25);
54 }
55 {
56 auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
57 int (*fp)(int) = L;
58 char (*fc)(char) = L; //expected-error{{no viable conversion}}
59 double (*fd)(double) = L; //expected-error{{no viable conversion}}
60 }
61 {
62 int x = 5;
63 auto L = [=](auto b, char c = 'x') {
64 int i = x;
65 return [](auto a) ->decltype(a) { return a; };
66 };
67 int (*fp)(int) = L(8);
68 fp(5);
69 L(3);
70 char (*fc)(char) = L('a');
71 fc('b');
72 L('c');
73 double (*fd)(double) = L(3.14);
74 fd(3.14);
75 fd(6.26);
76
77 }
78 {
79 auto L = [=](auto b) {
80 return [](auto a) ->decltype(b)* { return (decltype(b)*)0; };
81 };
82 int* (*fp)(int) = L(8);
83 fp(5);
84 L(3);
85 char* (*fc)(char) = L('a');
86 fc('b');
87 L('c');
88 double* (*fd)(double) = L(3.14);
89 fd(3.14);
90 fd(6.26);
91 }
92 {
93 auto L = [=](auto b) {
94 return [](auto a) ->decltype(b)* { return (decltype(b)*)0; }; //expected-note{{candidate template ignored}}
95 };
96 char* (*fp)(int) = L('8');
97 fp(5);
98 char* (*fc)(char) = L('a');
99 fc('b');
100 double* (*fi)(int) = L(3.14);
101 fi(5);
102 int* (*fi2)(int) = L(3.14); //expected-error{{no viable conversion}}
103 }
104
105 {
106 auto L = [=](auto b) {
107 return [](auto a) {
108 return [=](auto c) {
109 return [](auto d) ->decltype(a + b + c + d) { return d; };
110 };
111 };
112 };
113 int (*fp)(int) = L('8')(3)(short{});
114 double (*fs)(char) = L(3.14)(short{})('4');
115 }
116
117 fooT(3);
118 fooT('a');
119 fooT(3.14);
120 fooT("abcdefg");
121 return 0;
122 }
123 int run2 = test();
124
125 }
126
127
128 namespace test_conversion_to_fptr {
129
f1(int (*)(int))130 void f1(int (*)(int)) { }
f2(char (*)(int))131 void f2(char (*)(int)) { } // expected-note{{candidate}}
g(int (*)(int))132 void g(int (*)(int)) { } // #1 expected-note{{candidate}}
g(char (*)(char))133 void g(char (*)(char)) { } // #2 expected-note{{candidate}}
h(int (*)(int))134 void h(int (*)(int)) { } // #3
h(char (*)(int))135 void h(char (*)(int)) { } // #4
136
test()137 int test() {
138 {
139 auto glambda = [](auto a) { return a; };
140 glambda(1);
141 f1(glambda); // OK
142 f2(glambda); // expected-error{{no matching function}}
143 g(glambda); // expected-error{{call to 'g' is ambiguous}}
144 h(glambda); // OK: calls #3 since it is convertible from ID
145
146 int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
147
148 }
149 {
150
151 auto L = [](auto a) { return a; };
152 int (*fp)(int) = L;
153 fp(5);
154 L(3);
155 char (*fc)(char) = L;
156 fc('b');
157 L('c');
158 double (*fd)(double) = L;
159 fd(3.14);
160 fd(6.26);
161 L(4.25);
162 }
163 {
164 auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
165 int (*fp)(int) = L;
166 char (*fc)(char) = L; //expected-error{{no viable conversion}}
167 double (*fd)(double) = L; //expected-error{{no viable conversion}}
168 }
169 {
170 int* (*fp)(int*) = [](auto *a) -> auto* { return a; };
171 fp(0);
172 }
173 }
174
175 namespace more_converion_to_ptr_to_function_tests {
176
177
test()178 int test() {
179 {
180 int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
181 int (*fp2)(int) = [](auto b) -> int { return b; };
182 int (*fp3)(char) = [](auto c) -> int { return c; };
183 char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
184 //expected-note{{candidate template ignored}}
185 char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
186 //expected-note{{candidate template ignored}}
187
188 fp2(3);
189 fp3('\n');
190 fp3('a');
191 return 0;
192 }
193 } // end test()
194
vfun(Ts...)195 template<class ... Ts> void vfun(Ts ... ) { }
196
variadic_test()197 int variadic_test() {
198
199 int (*fp)(int, char, double) = [](auto ... a) -> int { vfun(a...); return 4; };
200 fp(3, '4', 3.14);
201
202 int (*fp2)(int, char, double) = [](auto ... a) { vfun(a...); return 4; };
203 fp(3, '4', 3.14);
204 return 2;
205 }
206
207 } // end ns
208
209 namespace conversion_operator {
test()210 void test() {
211 auto L = [](auto a) -> int { return a; };
212 int (*fp)(int) = L;
213 int (&fp2)(int) = [](auto a) { return a; }; // expected-error{{non-const lvalue}}
214 int (&&fp3)(int) = [](auto a) { return a; }; // expected-error{{no viable conversion}}\
215 //expected-note{{candidate}}
216 }
217 }
218 }
219
220 namespace return_type_deduction_ok {
__anondcda5c7e1e02(auto a) 221 auto l = [](auto a) ->auto { return a; }(2);
222 auto l2 = [](auto a) ->decltype(auto) { return a; }(2);
__anondcda5c7e1f02(auto a) 223 auto l3 = [](auto a) { return a; }(2);
224
225 }
226
227 namespace generic_lambda_as_default_argument_ok {
test(int i=[](auto a)->int{}(3))228 void test(int i = [](auto a)->int { return a; }(3)) {
229 }
230 }
231
232 namespace nested_non_capturing_lambda_tests {
print(Ts...)233 template<class ... Ts> void print(Ts ...) { }
test()234 int test() {
235 {
236 auto L = [](auto a) {
237 return [](auto b) {
238 return b;
239 };
240 };
241 auto M = L(3);
242 M(4.15);
243 }
244 {
245 int i = 10; //expected-note 3{{declared here}}
246 auto L = [](auto a) {
247 return [](auto b) { //expected-note 3{{begins here}}
248 i = b; //expected-error 3{{cannot be implicitly captured}}
249 return b;
250 };
251 };
252 auto M = L(3); //expected-note{{instantiation}}
253 M(4.15); //expected-note{{instantiation}}
254 }
255 {
256 int i = 10;
257 auto L = [](auto a) {
258 return [](auto b) {
259 b = sizeof(i); //ok
260 return b;
261 };
262 };
263 }
264 {
265 auto L = [](auto a) {
266 print("a = ", a, "\n");
267 return [](auto b) ->decltype(a) {
268 print("b = ", b, "\n");
269 return b;
270 };
271 };
272 auto M = L(3);
273 M(4.15);
274 }
275
276 {
277 auto L = [](auto a) ->decltype(a) {
278 print("a = ", a, "\n");
279 return [](auto b) ->decltype(a) { //expected-error{{no viable conversion}}\
280 //expected-note{{candidate template ignored}}
281 print("b = ", b, "\n");
282 return b;
283 };
284 };
285 auto M = L(3); //expected-note{{in instantiation of}}
286 }
287 {
288 auto L = [](auto a) {
289 print("a = ", a, "\n");
290 return [](auto ... b) ->decltype(a) {
291 print("b = ", b ..., "\n");
292 return 4;
293 };
294 };
295 auto M = L(3);
296 M(4.15, 3, "fv");
297 }
298
299 {
300 auto L = [](auto a) {
301 print("a = ", a, "\n");
302 return [](auto ... b) ->decltype(a) {
303 print("b = ", b ..., "\n");
304 return 4;
305 };
306 };
307 auto M = L(3);
308 int (*fp)(double, int, const char*) = M;
309 fp(4.15, 3, "fv");
310 }
311
312 {
313 auto L = [](auto a) {
314 print("a = ", a, "\n");
315 return [](char b) {
316 return [](auto ... c) ->decltype(b) {
317 print("c = ", c ..., "\n");
318 return 42;
319 };
320 };
321 };
322 L(4);
323 auto M = L(3);
324 M('a');
325 auto N = M('x');
326 N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
327 char (*np)(const char*, int, const char*, double, const char*, int) = N;
328 np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
329 }
330
331
332 {
333 auto L = [](auto a) {
334 print("a = ", a, "\n");
335 return [](decltype(a) b) {
336 return [](auto ... c) ->decltype(b) {
337 print("c = ", c ..., "\n");
338 return 42;
339 };
340 };
341 };
342 L('4');
343 auto M = L('3');
344 M('a');
345 auto N = M('x');
346 N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
347 char (*np)(const char*, int, const char*, double, const char*, int) = N;
348 np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
349 }
350
351
352 {
353 struct X {
354 static void foo(double d) { }
355 void test() {
356 auto L = [](auto a) {
357 print("a = ", a, "\n");
358 foo(a);
359 return [](decltype(a) b) {
360 foo(b);
361 foo(sizeof(a) + sizeof(b));
362 return [](auto ... c) ->decltype(b) {
363 print("c = ", c ..., "\n");
364 foo(decltype(b){});
365 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
366 return 42;
367 };
368 };
369 };
370 L('4');
371 auto M = L('3');
372 M('a');
373 auto N = M('x');
374 N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
375 char (*np)(const char*, int, const char*, double, const char*, int) = N;
376 np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
377 }
378 };
379 X x;
380 x.test();
381 }
382 // Make sure we can escape the function
383 {
384 struct X {
385 static void foo(double d) { }
386 auto test() {
387 auto L = [](auto a) {
388 print("a = ", a, "\n");
389 foo(a);
390 return [](decltype(a) b) {
391 foo(b);
392 foo(sizeof(a) + sizeof(b));
393 return [](auto ... c) ->decltype(b) {
394 print("c = ", c ..., "\n");
395 foo(decltype(b){});
396 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
397 return 42;
398 };
399 };
400 };
401 return L;
402 }
403 };
404 X x;
405 auto L = x.test();
406 L('4');
407 auto M = L('3');
408 M('a');
409 auto N = M('x');
410 N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
411 char (*np)(const char*, int, const char*, double, const char*, int) = N;
412 np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
413 }
414
415 {
416 struct X {
417 static void foo(double d) { }
418 auto test() {
419 auto L = [](auto a) {
420 print("a = ", a, "\n");
421 foo(a);
422 return [](decltype(a) b) {
423 foo(b);
424 foo(sizeof(a) + sizeof(b));
425 return [](auto ... c) {
426 print("c = ", c ..., "\n");
427 foo(decltype(b){});
428 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
429 return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
430 print("d = ", d ..., "\n");
431 foo(decltype(b){});
432 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
433 return decltype(a){};
434 };
435 };
436 };
437 };
438 return L;
439 }
440 };
441 X x;
442 auto L = x.test();
443 L('4');
444 auto M = L('3');
445 M('a');
446 auto N = M('x');
447 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
448 char (*np)(const char*, int, const char*, double, const char*, int) = O;
449 np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
450 int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
451
452 }
453 } // end test()
454
455 namespace wrapped_within_templates {
456
457 namespace explicit_return {
fooT(T t)458 template<class T> int fooT(T t) {
459 auto L = [](auto a) -> void {
460 auto M = [](char b) -> void {
461 auto N = [](auto c) -> void {
462 int x = 0;
463 x = sizeof(a);
464 x = sizeof(b);
465 x = sizeof(c);
466 };
467 N('a');
468 N(decltype(a){});
469 };
470 };
471 L(t);
472 L(3.14);
473 return 0;
474 }
475
476 int run = fooT('a') + fooT(3.14);
477
478 } // end explicit_return
479
480 namespace implicit_return_deduction {
fooT(T t)481 template<class T> auto fooT(T t) {
482 auto L = [](auto a) {
483 auto M = [](char b) {
484 auto N = [](auto c) {
485 int x = 0;
486 x = sizeof(a);
487 x = sizeof(b);
488 x = sizeof(c);
489 };
490 N('a');
491 N(decltype(a){});
492 };
493 };
494 L(t);
495 L(3.14);
496 return 0;
497 }
498
499 int run = fooT('a') + fooT(3.14);
500
print(Ts...ts)501 template<class ... Ts> void print(Ts ... ts) { }
502
fooV(Ts...ts)503 template<class ... Ts> auto fooV(Ts ... ts) {
504 auto L = [](auto ... a) {
505 auto M = [](decltype(a) ... b) {
506 auto N = [](auto c) {
507 int x = 0;
508 x = sizeof...(a);
509 x = sizeof...(b);
510 x = sizeof(c);
511 };
512 N('a');
513 N(N);
514 N(first<Ts...>{});
515 };
516 M(a...);
517 print("a = ", a..., "\n");
518 };
519 L(L, ts...);
520 print("ts = ", ts..., "\n");
521 return 0;
522 }
523
524 int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
525
526 } //implicit_return_deduction
527
528
529 } //wrapped_within_templates
530
531 namespace at_ns_scope {
foo(double d)532 void foo(double d) { }
test()533 auto test() {
534 auto L = [](auto a) {
535 print("a = ", a, "\n");
536 foo(a);
537 return [](decltype(a) b) {
538 foo(b);
539 foo(sizeof(a) + sizeof(b));
540 return [](auto ... c) {
541 print("c = ", c ..., "\n");
542 foo(decltype(b){});
543 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
544 return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
545 print("d = ", d ..., "\n");
546 foo(decltype(b){});
547 foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
548 return decltype(a){};
549 };
550 };
551 };
552 };
553 return L;
554 }
555 auto L = test();
556 auto L_test = L('4');
557 auto M = L('3');
558 auto M_test = M('a');
559 auto N = M('x');
560 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
561 char (*np)(const char*, int, const char*, double, const char*, int) = O;
562 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
563 int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
564
565
566
567 }
568
569 namespace variadic_tests_1 {
print(Ts...ts)570 template<class ... Ts> void print(Ts ... ts) { }
571
FirstArg(F & f,Rest...)572 template<class F, class ... Rest> F& FirstArg(F& f, Rest...) { return f; }
573
fooV(Ts...ts)574 template<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(first<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
595 int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
596
597 namespace more_variadic_1 {
598
fooV(Ts...ts)599 template<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(first<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(first<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
647 int 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
654 namespace at_ns_scope_within_class_member {
655 struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X656 static void foo(double d) { }
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X657 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 };
680 X x;
681 auto L = x.test();
682 auto L_test = L('4');
683 auto M = L('3');
684 auto M_test = M('a');
685 auto N = M('x');
686 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
687 char (*np)(const char*, int, const char*, double, const char*, int) = O;
688 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
689 int (*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
694 namespace at_ns_scope_within_class_template_member {
695 struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X696 static void foo(double d) { }
697 template<class T = int>
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X698 auto test(T = T{}) {
__anondcda5c7e4d02(auto a) 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 };
722 X x;
723 auto L = x.test();
724 auto L_test = L('4');
725 auto M = L('3');
726 auto M_test = M('a');
727 auto N = M('x');
728 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
729 char (*np)(const char*, int, const char*, double, const char*, int) = O;
730 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
731 int (*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
736 namespace nested_generic_lambdas_123 {
test()737 void 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 }
foo(T)746 template<class T> void foo(T) {
747 auto L = [](auto a) { return a; };
748 }
749 template void foo(int);
750 } // end ns nested_generic_lambdas_123
751
752 namespace nested_fptr_235 {
test()753 int 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 }
769 int run = test();
770 }
771
772
773 namespace fptr_with_decltype_return_type {
FirstArg(F & f,Rest &...r)774 template<class F, class ... Rest> F& FirstArg(F& f, Rest& ... r) { return f; };
vfun(Ts &&...ts)775 template<class ... Ts> auto vfun(Ts&& ... ts) {
776 print(ts...);
777 return FirstArg(ts...);
778 }
test()779 int test()
780 {
781 {
782 auto L = [](auto ... As) {
783 return [](auto b) ->decltype(b) {
784 vfun([](decltype(As) a) -> decltype(a) { return a; } ...)(first<decltype(As)...>{});
785 return decltype(b){};
786 };
787 };
788 auto LL = L(1, 'a', 3.14, "abc");
789 LL("dim");
790 }
791 return 0;
792 }
793 int run = test();
794 }
795
796 } // end ns nested_non_capturing_lambda_tests
797
798 namespace PR17476 {
799 struct string {
stringPR17476::string800 string(const char *__s) { }
operator +=PR17476::string801 string &operator+=(const string &__str) { return *this; }
802 };
803
804 template <class T>
finalizeDefaultAtomValues()805 void finalizeDefaultAtomValues() {
806 auto startEnd = [](const char * sym) -> void {
807 string start("__");
808 start += sym;
809 };
810 startEnd("preinit_array");
811 }
812
f()813 void f() { finalizeDefaultAtomValues<char>(); }
814
815 }
816
817 namespace PR17476_variant {
818 struct string {
stringPR17476_variant::string819 string(const char *__s) { }
operator +=PR17476_variant::string820 string &operator+=(const string &__str) { return *this; }
821 };
822
823 template <class T>
finalizeDefaultAtomValues()824 void finalizeDefaultAtomValues() {
825 auto startEnd = [](const T *sym) -> void {
826 string start("__");
827 start += sym;
828 };
829 startEnd("preinit_array");
830 }
831
f()832 void f() { finalizeDefaultAtomValues<char>(); }
833
834 }
835
836 namespace PR17877_lambda_declcontext_and_get_cur_lambda_disconnect {
837
838
839 template<class T> struct U {
840 int t = 0;
841 };
842
843 template<class T>
844 struct V {
sizePR17877_lambda_declcontext_and_get_cur_lambda_disconnect::V845 U<T> size() const { return U<T>{}; }
846 };
847
848 template<typename T>
Do()849 void Do() {
850 V<int> v{};
851 [=] { v.size(); };
852 }
853
854 }
855
856 namespace inclass_lambdas_within_nested_classes {
857 namespace ns1 {
858
859 struct X1 {
860 struct X2 {
__anondcda5c7e5902(auto i) 861 enum { E = [](auto i) { return i; }(3) }; //expected-error{{inside of a constant expression}}\
862 //expected-error{{constant}}\
863 //expected-note{{non-literal type}}
__anondcda5c7e5a02inclass_lambdas_within_nested_classes::ns1::X1::X2864 int L = ([] (int i) { return i; })(2);
fooinclass_lambdas_within_nested_classes::ns1::X1::X2865 void foo(int i = ([] (int i) { return i; })(2)) { }
__anondcda5c7e5c02inclass_lambdas_within_nested_classes::ns1::X1::X2866 int B : ([](int i) { return i; })(3); //expected-error{{inside of a constant expression}}\
867 //expected-error{{not an integral constant}}\
868 //expected-note{{non-literal type}}
__anondcda5c7e5d02inclass_lambdas_within_nested_classes::ns1::X1::X2869 int arr[([](int i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
870 //expected-error{{must have a constant size}}
__anondcda5c7e5e02inclass_lambdas_within_nested_classes::ns1::X1::X2871 int (*fp)(int) = [](int i) { return i; };
fooptrinclass_lambdas_within_nested_classes::ns1::X1::X2872 void fooptr(int (*fp)(char) = [](char c) { return 0; }) { }
__anondcda5c7e6002inclass_lambdas_within_nested_classes::ns1::X1::X2873 int L2 = ([](auto i) { return i; })(2);
fooGinclass_lambdas_within_nested_classes::ns1::X1::X2874 void fooG(int i = ([] (auto i) { return i; })(2)) { }
__anondcda5c7e6202inclass_lambdas_within_nested_classes::ns1::X1::X2875 int BG : ([](auto i) { return i; })(3); //expected-error{{inside of a constant expression}} \
876 //expected-error{{not an integral constant}}\
877 //expected-note{{non-literal type}}
__anondcda5c7e6302inclass_lambdas_within_nested_classes::ns1::X1::X2878 int arrG[([](auto i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
879 //expected-error{{must have a constant size}}
__anondcda5c7e6402inclass_lambdas_within_nested_classes::ns1::X1::X2880 int (*fpG)(int) = [](auto i) { return i; };
fooptrGinclass_lambdas_within_nested_classes::ns1::X1::X2881 void fooptrG(int (*fp)(char) = [](auto c) { return 0; }) { }
882 };
883 };
884 } //end ns
885
886 namespace ns2 {
887 struct X1 {
888 template<class T>
889 struct X2 {
__anondcda5c7e6602inclass_lambdas_within_nested_classes::ns2::X1::X2890 int L = ([] (T i) { return i; })(2);
fooinclass_lambdas_within_nested_classes::ns2::X1::X2891 void foo(int i = ([] (int i) { return i; })(2)) { }
__anondcda5c7e6802inclass_lambdas_within_nested_classes::ns2::X1::X2892 int B : ([](T i) { return i; })(3); //expected-error{{inside of a constant expression}}\
893 //expected-error{{not an integral constant}}\
894 //expected-note{{non-literal type}}
__anondcda5c7e6902inclass_lambdas_within_nested_classes::ns2::X1::X2895 int arr[([](T i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
896 //expected-error{{must have a constant size}}
__anondcda5c7e6a02inclass_lambdas_within_nested_classes::ns2::X1::X2897 int (*fp)(T) = [](T i) { return i; };
fooptrinclass_lambdas_within_nested_classes::ns2::X1::X2898 void fooptr(T (*fp)(char) = [](char c) { return 0; }) { }
__anondcda5c7e6c02inclass_lambdas_within_nested_classes::ns2::X1::X2899 int L2 = ([](auto i) { return i; })(2);
fooGinclass_lambdas_within_nested_classes::ns2::X1::X2900 void fooG(T i = ([] (auto i) { return i; })(2)) { }
__anondcda5c7e6e02inclass_lambdas_within_nested_classes::ns2::X1::X2901 int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}\
902 //expected-note{{non-literal type}}\
903 //expected-error{{inside of a constant expression}}
__anondcda5c7e6f02inclass_lambdas_within_nested_classes::ns2::X1::X2904 int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}} \
905 //expected-error{{inside of a constant expression}}
__anondcda5c7e7002inclass_lambdas_within_nested_classes::ns2::X1::X2906 int (*fpG)(T) = [](auto i) { return i; };
fooptrGinclass_lambdas_within_nested_classes::ns2::X1::X2907 void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }
fooG2inclass_lambdas_within_nested_classes::ns2::X1::X2908 template<class U = char> int fooG2(T (*fp)(U) = [](auto a) { return 0; }) { return 0; }
__anondcda5c7e7302inclass_lambdas_within_nested_classes::ns2::X1::X2909 template<class U = char> int fooG3(T (*fp)(U) = [](auto a) { return 0; });
910 };
911 };
912 template<class T>
913 template<class U>
fooG3(T (* fp)(U))914 int X1::X2<T>::fooG3(T (*fp)(U)) { return 0; }
915 X1::X2<int> x2; //expected-note 3{{in instantiation of}}
916 int run1 = x2.fooG2();
917 int run2 = x2.fooG3();
918 } // end ns
919
920
921
922 } //end ns inclass_lambdas_within_nested_classes
923
924 namespace pr21684_disambiguate_auto_followed_by_ellipsis_no_id {
__anondcda5c7e7402(auto ...) 925 int a = [](auto ...) { return 0; }();
926 }
927
928 namespace PR22117 {
__anondcda5c7e7502(auto) 929 int x = [](auto) {
930 return [](auto... run_args) {
931 using T = int(decltype(run_args)...);
932 return 0;
933 };
934 }(0)(0);
935 }
936
937 namespace PR23716 {
938 template<typename T>
f(T x)939 auto f(T x) {
940 auto g = [](auto&&... args) {
941 auto h = [args...]() -> int {
942 return 0;
943 };
944 return h;
945 };
946 return g;
947 }
948
949 auto x = f(0)();
950 }
951
952 namespace PR13987 {
953 class Enclosing {
__anondcda5c7e7902()954 void Method(char c = []()->char {
955 int d = [](auto x)->int {
956 struct LocalClass {
957 int Method() { return 0; }
958 };
959 return 0;
960 }(0);
961 return d; }()
962 );
963 };
964
965 class Enclosing2 {
__anondcda5c7e7b02(auto x)966 void Method(char c = [](auto x)->char {
967 int d = []()->int {
968 struct LocalClass {
969 int Method() { return 0; }
970 };
971 return 0;
972 }();
973 return d; }(0)
974 );
975 };
976
977 class Enclosing3 {
__anondcda5c7e7d02(auto x)978 void Method(char c = [](auto x)->char {
979 int d = [](auto y)->int {
980 struct LocalClass {
981 int Method() { return 0; }
982 };
983 return 0;
984 }(0);
985 return d; }(0)
986 );
987 };
988 }
989