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 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows-pc -emit-llvm-only %s
6 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows-pc -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
7 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows-pc -fms-extensions %s -DMS_EXTENSIONS
8 // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -triple i386-windows-pc -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
9 
10 template<class F, class ...Rest> struct first_impl { typedef F type; };
11 template<class ...Args> using first = typename first_impl<Args...>::type;
12 
13 namespace simple_explicit_capture {
test()14   void test() {
15     int i;
16     auto L = [i](auto a) { return i + a; };
17     L(3.14);
18   }
19 }
20 
21 namespace explicit_call {
test()22 int test() {
23   auto L = [](auto a) { return a; };
24   L.operator()(3);
25   L.operator()<char>(3.14); //expected-warning{{implicit conversion}}
26   return 0;
27 }
28 } //end ns
29 
30 namespace test_conversion_to_fptr_2 {
31 
32 template<class T> struct X {
33 
__anon1571c8ff0302test_conversion_to_fptr_2::X34   T (*fp)(T) = [](auto a) { return a; };
35 
36 };
37 
38 X<int> xi;
39 
40 template<class T>
__anon1571c8ff0402(auto a) 41 void fooT(T t, T (*fp)(T) = [](auto a) { return a; }) {
42   fp(t);
43 }
44 
test()45 int test() {
46 {
47   auto L = [](auto a) { return a; };
48   int (*fp)(int) = L;
49   fp(5);
50   L(3);
51   char (*fc)(char) = L;
52   fc('b');
53   L('c');
54   double (*fd)(double) = L;
55   fd(3.14);
56   fd(6.26);
57   L(4.25);
58 }
59 {
60   auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
61   int (*fp)(int) = L;
62   char (*fc)(char) = L; //expected-error{{no viable conversion}}
63   double (*fd)(double) = L; //expected-error{{no viable conversion}}
64 }
65 {
66   int x = 5;
67   auto L = [=](auto b, char c = 'x') {
68     int i = x;
69     return [](auto a) ->decltype(a) { return a; };
70   };
71   int (*fp)(int) = L(8);
72   fp(5);
73   L(3);
74   char (*fc)(char) = L('a');
75   fc('b');
76   L('c');
77   double (*fd)(double) = L(3.14);
78   fd(3.14);
79   fd(6.26);
80 
81 }
82 {
83  auto L = [=](auto b) {
84     return [](auto a) ->decltype(b)* { return (decltype(b)*)0; };
85   };
86   int* (*fp)(int) = L(8);
87   fp(5);
88   L(3);
89   char* (*fc)(char) = L('a');
90   fc('b');
91   L('c');
92   double* (*fd)(double) = L(3.14);
93   fd(3.14);
94   fd(6.26);
95 }
96 {
97  auto L = [=](auto b) {
98     return [](auto a) ->decltype(b)* { return (decltype(b)*)0; }; //expected-note{{candidate template ignored}}
99   };
100   char* (*fp)(int) = L('8');
101   fp(5);
102   char* (*fc)(char) = L('a');
103   fc('b');
104   double* (*fi)(int) = L(3.14);
105   fi(5);
106   int* (*fi2)(int) = L(3.14); //expected-error{{no viable conversion}}
107 }
108 
109 {
110  auto L = [=](auto b) {
111     return [](auto a) {
112       return [=](auto c) {
113         return [](auto d) ->decltype(a + b + c + d) { return d; };
114       };
115     };
116   };
117   int (*fp)(int) = L('8')(3)(short{});
118   double (*fs)(char) = L(3.14)(short{})('4');
119 }
120 
121   fooT(3);
122   fooT('a');
123   fooT(3.14);
124   fooT("abcdefg");
125   return 0;
126 }
127 int run2 = test();
128 
129 }
130 
131 
132 namespace test_conversion_to_fptr {
133 
f1(int (*)(int))134 void f1(int (*)(int)) { }
f2(char (*)(int))135 void f2(char (*)(int)) { } // expected-note{{candidate}}
g(int (*)(int))136 void g(int (*)(int)) { } // #1 expected-note{{candidate}}
g(char (*)(char))137 void g(char (*)(char)) { } // #2 expected-note{{candidate}}
h(int (*)(int))138 void h(int (*)(int)) { } // #3
h(char (*)(int))139 void h(char (*)(int)) { } // #4
140 
test()141 int test() {
142 {
143   auto glambda = [](auto a) { return a; };
144   glambda(1);
145   f1(glambda); // OK
146   f2(glambda); // expected-error{{no matching function}}
147   g(glambda); // expected-error{{call to 'g' is ambiguous}}
148   h(glambda); // OK: calls #3 since it is convertible from ID
149 
150   int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
151 
152 }
153 {
154 
155   auto L = [](auto a) { return a; };
156   int (*fp)(int) = L;
157   fp(5);
158   L(3);
159   char (*fc)(char) = L;
160   fc('b');
161   L('c');
162   double (*fd)(double) = L;
163   fd(3.14);
164   fd(6.26);
165   L(4.25);
166 }
167 {
168   auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
169   int (*fp)(int) = L;
170   char (*fc)(char) = L; //expected-error{{no viable conversion}}
171   double (*fd)(double) = L; //expected-error{{no viable conversion}}
172 }
173 {
174   int* (*fp)(int*) = [](auto *a) -> auto* { return a; };
175   fp(0);
176 }
177 }
178 
179 namespace more_converion_to_ptr_to_function_tests {
180 
181 
test()182 int test() {
183   {
184     int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
185     int (*fp2)(int) = [](auto b) -> int {  return b; };
186     int (*fp3)(char) = [](auto c) -> int { return c; };
187     char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
188                                                  //expected-note{{candidate function [with d:auto = int]}}
189     char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
190                                                  //expected-note{{candidate template ignored}}
191 
192     fp2(3);
193     fp3('\n');
194     fp3('a');
195     return 0;
196   }
197 } // end test()
198 
vfun(Ts...)199 template<class ... Ts> void vfun(Ts ... ) { }
200 
variadic_test()201 int variadic_test() {
202 
203  int (*fp)(int, char, double) = [](auto ... a) -> int { vfun(a...); return 4; };
204  fp(3, '4', 3.14);
205 
206  int (*fp2)(int, char, double) = [](auto ... a) { vfun(a...); return 4; };
207  fp(3, '4', 3.14);
208  return 2;
209 }
210 
211 } // end ns
212 
213 namespace conversion_operator {
test()214   void test() {
215     auto L = [](auto a) -> int { return a; }; // expected-error {{cannot initialize}}
216     int (*fp)(int) = L;
217     int (&fp2)(int) = [](auto a) { return a; };  // expected-error{{non-const lvalue}}
218     int (&&fp3)(int) = [](auto a) { return a; };  // expected-error{{no viable conversion}}\
219                                                   //expected-note{{candidate}}
220 
221     using F = int(int);
222     using G = int(void*);
223     L.operator F*();
224     L.operator G*(); // expected-note-re {{instantiation of function template specialization '{{.*}}::operator()<void *>'}}
225 
226     // Here, the conversion function is named 'operator auto (*)(int)', and
227     // there is no way to write that name in valid C++.
228     auto M = [](auto a) -> auto { return a; };
229     M.operator F*(); // expected-error {{no member named 'operator int (*)(int)'}}
230   }
231 }
232 }
233 
234 namespace return_type_deduction_ok {
__anon1571c8ff1f02(auto a) 235  auto l = [](auto a) ->auto { return a; }(2);
236  auto l2 = [](auto a) ->decltype(auto) { return a; }(2);
__anon1571c8ff2002(auto a) 237  auto l3 = [](auto a) { return a; }(2);
238 
239 }
240 
241 namespace generic_lambda_as_default_argument_ok {
test(int i=[](auto a)->int{}(3))242   void test(int i = [](auto a)->int { return a; }(3)) {
243   }
244 }
245 
246 namespace nested_non_capturing_lambda_tests {
print(Ts...)247 template<class ... Ts> void print(Ts ...) { }
test()248 int test() {
249 {
250   auto L = [](auto a) {
251     return [](auto b) {
252       return b;
253     };
254   };
255   auto M = L(3);
256   M(4.15);
257  }
258 {
259   int i = 10; //expected-note 3{{declared here}}
260   auto L = [](auto a) {
261     return [](auto b) { //expected-note 3{{begins here}}
262       i = b;  //expected-error 3{{cannot be implicitly captured}}
263       return b;
264     };
265   };
266   auto M = L(3); //expected-note{{instantiation}}
267   M(4.15); //expected-note{{instantiation}}
268  }
269  {
270   int i = 10;
271   auto L = [](auto a) {
272     return [](auto b) {
273       b = sizeof(i);  //ok
274       return b;
275     };
276   };
277  }
278  {
279   auto L = [](auto a) {
280     print("a = ", a, "\n");
281     return [](auto b) ->decltype(a) {
282       print("b = ", b, "\n");
283       return b;
284     };
285   };
286   auto M = L(3);
287   M(4.15);
288  }
289 
290 {
291   auto L = [](auto a) ->decltype(a) {
292     print("a = ", a, "\n");
293     return [](auto b) ->decltype(a) { //expected-error{{no viable conversion}}\
294                                       //expected-note{{candidate template ignored}}
295       print("b = ", b, "\n");
296       return b;
297     };
298   };
299   auto M = L(3); //expected-note{{in instantiation of}}
300  }
301 {
302   auto L = [](auto a) {
303     print("a = ", a, "\n");
304     return [](auto ... b) ->decltype(a) {
305       print("b = ", b ..., "\n");
306       return 4;
307     };
308   };
309   auto M = L(3);
310   M(4.15, 3, "fv");
311 }
312 
313 {
314   auto L = [](auto a) {
315     print("a = ", a, "\n");
316     return [](auto ... b) ->decltype(a) {
317       print("b = ", b ..., "\n");
318       return 4;
319     };
320   };
321   auto M = L(3);
322   int (*fp)(double, int, const char*) = M;
323   fp(4.15, 3, "fv");
324 }
325 
326 {
327   auto L = [](auto a) {
328     print("a = ", a, "\n");
329     return [](char b) {
330       return [](auto ... c) ->decltype(b) {
331         print("c = ", c ..., "\n");
332         return 42;
333       };
334     };
335   };
336   L(4);
337   auto M = L(3);
338   M('a');
339   auto N = M('x');
340   N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
341   char (*np)(const char*, int, const char*, double, const char*, int) = N;
342   np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
343 }
344 
345 
346 {
347   auto L = [](auto a) {
348     print("a = ", a, "\n");
349     return [](decltype(a) b) {
350       return [](auto ... c) ->decltype(b) {
351         print("c = ", c ..., "\n");
352         return 42;
353       };
354     };
355   };
356   L('4');
357   auto M = L('3');
358   M('a');
359   auto N = M('x');
360   N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
361   char (*np)(const char*, int, const char*, double, const char*, int) = N;
362   np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
363 }
364 
365 
366 {
367  struct X {
368   static void foo(double d) { }
369   void test() {
370     auto L = [](auto a) {
371       print("a = ", a, "\n");
372       foo(a);
373       return [](decltype(a) b) {
374         foo(b);
375         foo(sizeof(a) + sizeof(b));
376         return [](auto ... c) ->decltype(b) {
377           print("c = ", c ..., "\n");
378           foo(decltype(b){});
379           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
380           return 42;
381         };
382       };
383     };
384     L('4');
385     auto M = L('3');
386     M('a');
387     auto N = M('x');
388     N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
389     char (*np)(const char*, int, const char*, double, const char*, int) = N;
390     np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
391   }
392 };
393 X x;
394 x.test();
395 }
396 // Make sure we can escape the function
397 {
398  struct X {
399   static void foo(double d) { }
400   auto test() {
401     auto L = [](auto a) {
402       print("a = ", a, "\n");
403       foo(a);
404       return [](decltype(a) b) {
405         foo(b);
406         foo(sizeof(a) + sizeof(b));
407         return [](auto ... c) ->decltype(b) {
408           print("c = ", c ..., "\n");
409           foo(decltype(b){});
410           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
411           return 42;
412         };
413       };
414     };
415     return L;
416   }
417 };
418   X x;
419   auto L = x.test();
420   L('4');
421   auto M = L('3');
422   M('a');
423   auto N = M('x');
424   N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
425   char (*np)(const char*, int, const char*, double, const char*, int) = N;
426   np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
427 }
428 
429 {
430  struct X {
431   static void foo(double d) { }
432   auto test() {
433     auto L = [](auto a) {
434       print("a = ", a, "\n");
435       foo(a);
436       return [](decltype(a) b) {
437         foo(b);
438         foo(sizeof(a) + sizeof(b));
439         return [](auto ... c) {
440           print("c = ", c ..., "\n");
441           foo(decltype(b){});
442           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
443           return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
444             print("d = ", d ..., "\n");
445             foo(decltype(b){});
446             foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
447             return decltype(a){};
448           };
449         };
450       };
451     };
452     return L;
453   }
454 };
455   X x;
456   auto L = x.test();
457   L('4');
458   auto M = L('3');
459   M('a');
460   auto N = M('x');
461   auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
462   char (*np)(const char*, int, const char*, double, const char*, int) = O;
463   np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
464   int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
465 
466 }
467 } // end test()
468 
469 namespace wrapped_within_templates {
470 
471 namespace explicit_return {
fooT(T t)472 template<class T> int fooT(T t) {
473   auto L = [](auto a) -> void {
474     auto M = [](char b) -> void {
475       auto N = [](auto c) -> void {
476         int x = 0;
477         x = sizeof(a);
478         x = sizeof(b);
479         x = sizeof(c);
480       };
481       N('a');
482       N(decltype(a){});
483     };
484   };
485   L(t);
486   L(3.14);
487   return 0;
488 }
489 
490 int run = fooT('a') + fooT(3.14);
491 
492 } // end explicit_return
493 
494 namespace implicit_return_deduction {
fooT(T t)495 template<class T> auto fooT(T t) {
496   auto L = [](auto a)  {
497     auto M = [](char b)  {
498       auto N = [](auto c)  {
499         int x = 0;
500         x = sizeof(a);
501         x = sizeof(b);
502         x = sizeof(c);
503       };
504       N('a');
505       N(decltype(a){});
506     };
507   };
508   L(t);
509   L(3.14);
510   return 0;
511 }
512 
513 int run = fooT('a') + fooT(3.14);
514 
print(Ts...ts)515 template<class ... Ts> void print(Ts ... ts) { }
516 
fooV(Ts...ts)517 template<class ... Ts> auto fooV(Ts ... ts) {
518   auto L = [](auto ... a) {
519     auto M = [](decltype(a) ... b) {
520       auto N = [](auto c) {
521         int x = 0;
522         x = sizeof...(a);
523         x = sizeof...(b);
524         x = sizeof(c);
525       };
526       N('a');
527       N(N);
528       N(first<Ts...>{});
529     };
530     M(a...);
531     print("a = ", a..., "\n");
532   };
533   L(L, ts...);
534   print("ts = ", ts..., "\n");
535   return 0;
536 }
537 
538 int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
539 
540 } //implicit_return_deduction
541 
542 
543 } //wrapped_within_templates
544 
545 namespace at_ns_scope {
foo(double d)546   void foo(double d) { }
test()547   auto test() {
548     auto L = [](auto a) {
549       print("a = ", a, "\n");
550       foo(a);
551       return [](decltype(a) b) {
552         foo(b);
553         foo(sizeof(a) + sizeof(b));
554         return [](auto ... c) {
555           print("c = ", c ..., "\n");
556           foo(decltype(b){});
557           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
558           return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
559             print("d = ", d ..., "\n");
560             foo(decltype(b){});
561             foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
562             return decltype(a){};
563           };
564         };
565       };
566     };
567     return L;
568   }
569 auto L = test();
570 auto L_test = L('4');
571 auto M = L('3');
572 auto M_test = M('a');
573 auto N = M('x');
574 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
575 char (*np)(const char*, int, const char*, double, const char*, int) = O;
576 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
577 int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
578 
579 
580 
581 }
582 
583 namespace variadic_tests_1 {
print(Ts...ts)584 template<class ... Ts> void print(Ts ... ts) { }
585 
586 template<class F, class ... Rest> F& FirstArg(F& f, Rest...) { return f; }
587 
fooV(Ts...ts)588 template<class ... Ts> int fooV(Ts ... ts) {
589   auto L = [](auto ... a) -> void {
590     auto M = [](decltype(a) ... b) -> void {
591       auto N = [](auto c) -> void {
592         int x = 0;
593         x = sizeof...(a);
594         x = sizeof...(b);
595         x = sizeof(c);
596       };
597       N('a');
598       N(N);
599       N(first<Ts...>{});
600     };
601     M(a...);
602     print("a = ", a..., "\n");
603   };
604   L(L, ts...);
605   print("ts = ", ts..., "\n");
606   return 0;
607 }
608 
609 int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
610 
611 namespace more_variadic_1 {
612 
fooV(Ts...ts)613 template<class ... Ts> int fooV(Ts ... ts) {
614   auto L = [](auto ... a) {
615     auto M = [](decltype(a) ... b) -> void {
616       auto N = [](auto c) -> void {
617         int x = 0;
618         x = sizeof...(a);
619         x = sizeof...(b);
620         x = sizeof(c);
621       };
622       N('a');
623       N(N);
624       N(first<Ts...>{});
625     };
626     M(a...);
627     return M;
628   };
629   auto M = L(L, ts...);
630   decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
631   void (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
632 
633   {
634     auto L = [](auto ... a) {
635       auto M = [](decltype(a) ... b) {
636         auto N = [](auto c) -> void {
637           int x = 0;
638           x = sizeof...(a);
639           x = sizeof...(b);
640           x = sizeof(c);
641         };
642         N('a');
643         N(N);
644         N(first<Ts...>{});
645         return N;
646       };
647       M(a...);
648       return M;
649     };
650     auto M = L(L, ts...);
651     decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
652     fp(L, ts...);
653     decltype(L(L, ts...)(L, ts...)) (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
654     fp2 = fp(L, ts...);
655     void (*fp3)(char) = fp2(L, ts...);
656     fp3('a');
657   }
658   return 0;
659 }
660 
661 int run2 = fooV(3.14, " ", '4', 5) + fooV("BC", 3, 2.77, 'A', float{}, short{}, unsigned{});
662 
663 
664 } //end ns more_variadic_1
665 
666 } // end ns variadic_tests_1
667 
668 namespace at_ns_scope_within_class_member {
669  struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X670   static void foo(double d) { }
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_member::X671   auto test() {
672     auto L = [](auto a) {
673       print("a = ", a, "\n");
674       foo(a);
675       return [](decltype(a) b) {
676         foo(b);
677         foo(sizeof(a) + sizeof(b));
678         return [](auto ... c) {
679           print("c = ", c ..., "\n");
680           foo(decltype(b){});
681           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
682           return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
683             print("d = ", d ..., "\n");
684             foo(decltype(b){});
685             foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
686             return decltype(a){};
687           };
688         };
689       };
690     };
691     return L;
692   }
693 };
694 X x;
695 auto L = x.test();
696 auto L_test = L('4');
697 auto M = L('3');
698 auto M_test = M('a');
699 auto N = M('x');
700 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
701 char (*np)(const char*, int, const char*, double, const char*, int) = O;
702 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
703 int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
704 
705 } //end at_ns_scope_within_class_member
706 
707 
708 namespace at_ns_scope_within_class_template_member {
709  struct X {
foonested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X710   static void foo(double d) { }
711   template<class T = int>
testnested_non_capturing_lambda_tests::at_ns_scope_within_class_template_member::X712   auto test(T = T{}) {
__anon1571c8ff4e02(auto a) 713     auto L = [](auto a) {
714       print("a = ", a, "\n");
715       foo(a);
716       return [](decltype(a) b) {
717         foo(b);
718         foo(sizeof(a) + sizeof(b));
719         return [](auto ... c) {
720           print("c = ", c ..., "\n");
721           foo(decltype(b){});
722           foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
723           return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
724             print("d = ", d ..., "\n");
725             foo(decltype(b){});
726             foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
727             return decltype(a){};
728           };
729         };
730       };
731     };
732     return L;
733   }
734 
735 };
736 X x;
737 auto L = x.test();
738 auto L_test = L('4');
739 auto M = L('3');
740 auto M_test = M('a');
741 auto N = M('x');
742 auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
743 char (*np)(const char*, int, const char*, double, const char*, int) = O;
744 auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
745 int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
746 
747 } //end at_ns_scope_within_class_member
748 
749 
750 namespace nested_generic_lambdas_123 {
test()751 void test() {
752   auto L = [](auto a) -> int {
753     auto M = [](auto b, decltype(a) b2) -> int {
754       return 1;
755     };
756     M(a, a);
757   };
758   L(3);
759 }
foo(T)760 template<class T> void foo(T) {
761  auto L = [](auto a) { return a; };
762 }
763 template void foo(int);
764 } // end ns nested_generic_lambdas_123
765 
766 namespace nested_fptr_235 {
test()767 int test()
768 {
769   auto L = [](auto b) {
770     return [](auto a) ->decltype(a) { return a; };
771   };
772   int (*fp)(int) = L(8);
773   fp(5);
774   L(3);
775   char (*fc)(char) = L('a');
776   fc('b');
777   L('c');
778   double (*fd)(double) = L(3.14);
779   fd(3.14);
780   fd(6.26);
781   return 0;
782 }
783 int run = test();
784 }
785 
786 
787 namespace fptr_with_decltype_return_type {
788 template<class F, class ... Rest> F& FirstArg(F& f, Rest& ... r) { return f; };
vfun(Ts &&...ts)789 template<class ... Ts> auto vfun(Ts&& ... ts) {
790   print(ts...);
791   return FirstArg(ts...);
792 }
test()793 int test()
794 {
795  {
796    auto L = [](auto ... As) {
797     return [](auto b) ->decltype(b) {
798       vfun([](decltype(As) a) -> decltype(a) { return a; } ...)(first<decltype(As)...>{});
799       return decltype(b){};
800     };
801    };
802    auto LL = L(1, 'a', 3.14, "abc");
803    LL("dim");
804  }
805   return 0;
806 }
807 int run = test();
808 }
809 
810 } // end ns nested_non_capturing_lambda_tests
811 
812 namespace PR17476 {
813 struct string {
stringPR17476::string814   string(const char *__s) { }
operator +=PR17476::string815   string &operator+=(const string &__str) { return *this; }
816 };
817 
818 template <class T>
finalizeDefaultAtomValues()819 void finalizeDefaultAtomValues() {
820   auto startEnd = [](const char * sym) -> void {
821     string start("__");
822     start += sym;
823   };
824   startEnd("preinit_array");
825 }
826 
f()827 void f() { finalizeDefaultAtomValues<char>(); }
828 
829 }
830 
831 namespace PR17476_variant {
832 struct string {
stringPR17476_variant::string833   string(const char *__s) { }
operator +=PR17476_variant::string834   string &operator+=(const string &__str) { return *this; }
835 };
836 
837 template <class T>
finalizeDefaultAtomValues()838 void finalizeDefaultAtomValues() {
839   auto startEnd = [](const T *sym) -> void {
840     string start("__");
841     start += sym;
842   };
843   startEnd("preinit_array");
844 }
845 
f()846 void f() { finalizeDefaultAtomValues<char>(); }
847 
848 }
849 
850 namespace PR17877_lambda_declcontext_and_get_cur_lambda_disconnect {
851 
852 
853 template<class T> struct U {
854   int t = 0;
855 };
856 
857 template<class T>
858 struct V {
sizePR17877_lambda_declcontext_and_get_cur_lambda_disconnect::V859   U<T> size() const { return U<T>{}; }
860 };
861 
862 template<typename T>
Do()863 void Do() {
864   V<int> v{};
865   [=] { v.size(); };
866 }
867 
868 }
869 
870 namespace inclass_lambdas_within_nested_classes {
871 namespace ns1 {
872 
873 struct X1 {
874   struct X2 {
__anon1571c8ff5a02(auto i) 875     enum { E = [](auto i) { return i; }(3) }; //expected-error{{inside of a constant expression}}\
876                                           //expected-error{{constant}}\
877                                           //expected-note{{non-literal type}}
__anon1571c8ff5b02inclass_lambdas_within_nested_classes::ns1::X1::X2878     int L = ([] (int i) { return i; })(2);
fooinclass_lambdas_within_nested_classes::ns1::X1::X2879     void foo(int i = ([] (int i) { return i; })(2)) { }
__anon1571c8ff5d02inclass_lambdas_within_nested_classes::ns1::X1::X2880     int B : ([](int i) { return i; })(3); //expected-error{{inside of a constant expression}}\
881                                           //expected-error{{not an integral constant}}\
882                                           //expected-note{{non-literal type}}
__anon1571c8ff5e02inclass_lambdas_within_nested_classes::ns1::X1::X2883     int arr[([](int i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
884                                            //expected-error{{must have a constant size}}
__anon1571c8ff5f02inclass_lambdas_within_nested_classes::ns1::X1::X2885     int (*fp)(int) = [](int i) { return i; };
fooptrinclass_lambdas_within_nested_classes::ns1::X1::X2886     void fooptr(int (*fp)(char) = [](char c) { return 0; }) { }
__anon1571c8ff6102inclass_lambdas_within_nested_classes::ns1::X1::X2887     int L2 = ([](auto i) { return i; })(2);
fooGinclass_lambdas_within_nested_classes::ns1::X1::X2888     void fooG(int i = ([] (auto i) { return i; })(2)) { }
__anon1571c8ff6302inclass_lambdas_within_nested_classes::ns1::X1::X2889     int BG : ([](auto i) { return i; })(3); //expected-error{{inside of a constant expression}}  \
890                                             //expected-error{{not an integral constant}}\
891                                             //expected-note{{non-literal type}}
__anon1571c8ff6402inclass_lambdas_within_nested_classes::ns1::X1::X2892     int arrG[([](auto i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
893                                              //expected-error{{must have a constant size}}
__anon1571c8ff6502inclass_lambdas_within_nested_classes::ns1::X1::X2894     int (*fpG)(int) = [](auto i) { return i; };
__anon1571c8ff6602inclass_lambdas_within_nested_classes::ns1::X1::X2895     void fooptrG(int (*fp)(char) = [](auto c) { return 0; }) { }
896   };
897 };
898 } //end ns
899 
900 namespace ns2 {
901 struct X1 {
902   template<class T>
903   struct X2 {
__anon1571c8ff6702inclass_lambdas_within_nested_classes::ns2::X1::X2904     int L = ([] (T i) { return i; })(2);
__anon1571c8ff6802inclass_lambdas_within_nested_classes::ns2::X1::X2905     void foo(int i = ([] (int i) { return i; })(2)) { }
__anon1571c8ff6902inclass_lambdas_within_nested_classes::ns2::X1::X2906     int B : ([](T i) { return i; })(3); //expected-error{{inside of a constant expression}}\
907                                         //expected-error{{not an integral constant}}\
908                                         //expected-note{{non-literal type}}
__anon1571c8ff6a02inclass_lambdas_within_nested_classes::ns2::X1::X2909     int arr[([](T i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
910                                          //expected-error{{must have a constant size}}
__anon1571c8ff6b02inclass_lambdas_within_nested_classes::ns2::X1::X2911     int (*fp)(T) = [](T i) { return i; };
fooptrinclass_lambdas_within_nested_classes::ns2::X1::X2912     void fooptr(T (*fp)(char) = [](char c) { return 0; }) { }
__anon1571c8ff6d02inclass_lambdas_within_nested_classes::ns2::X1::X2913     int L2 = ([](auto i) { return i; })(2);
__anon1571c8ff6e02inclass_lambdas_within_nested_classes::ns2::X1::X2914     void fooG(T i = ([] (auto i) { return i; })(2)) { }
__anon1571c8ff6f02inclass_lambdas_within_nested_classes::ns2::X1::X2915     int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}\
916                                             //expected-note{{non-literal type}}\
917                                             //expected-error{{inside of a constant expression}}
__anon1571c8ff7002inclass_lambdas_within_nested_classes::ns2::X1::X2918     int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}} \
919                                              //expected-error{{inside of a constant expression}}
__anon1571c8ff7102inclass_lambdas_within_nested_classes::ns2::X1::X2920     int (*fpG)(T) = [](auto i) { return i; };
fooptrGinclass_lambdas_within_nested_classes::ns2::X1::X2921     void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }
fooG2inclass_lambdas_within_nested_classes::ns2::X1::X2922     template<class U = char> int fooG2(T (*fp)(U) = [](auto a) { return 0; }) { return 0; }
__anon1571c8ff7402inclass_lambdas_within_nested_classes::ns2::X1::X2923     template<class U = char> int fooG3(T (*fp)(U) = [](auto a) { return 0; });
924   };
925 };
926 template<class T>
927 template<class U>
fooG3(T (* fp)(U))928 int X1::X2<T>::fooG3(T (*fp)(U)) { return 0; }
929 X1::X2<int> x2; //expected-note {{in instantiation of}}
930 int run1 = x2.fooG2();
931 int run2 = x2.fooG3();
932 } // end ns
933 
934 
935 
936 } //end ns inclass_lambdas_within_nested_classes
937 
938 namespace pr21684_disambiguate_auto_followed_by_ellipsis_no_id {
__anon1571c8ff7502(auto ...) 939 int a = [](auto ...) { return 0; }();
940 }
941 
942 namespace PR22117 {
__anon1571c8ff7602(auto) 943   int x = [](auto) {
944     return [](auto... run_args) {
945       using T = int(decltype(run_args)...);
946       return 0;
947     };
948   }(0)(0);
949 }
950 
951 namespace PR41139 {
__anon1571c8ff7802(auto outer) 952   int y = [](auto outer) {
953     return [](auto inner) {
954       using T = int(decltype(outer), decltype(inner));
955       return 0;
956     };
957   }(0)(0);
958 }
959 
960 namespace PR23716 {
961 template<typename T>
f(T x)962 auto f(T x) {
963   auto g = [](auto&&... args) {
964     auto h = [args...]() -> int {
965       return 0;
966     };
967     return h;
968   };
969   return g;
970 }
971 
972 auto x = f(0)();
973 }
974 
975 namespace PR13987 {
976 class Enclosing {
__anon1571c8ff7c02()977   void Method(char c = []()->char {
978     int d = [](auto x)->int {
979         struct LocalClass {
980           int Method() { return 0; }
981         };
982       return 0;
983     }(0);
984     return d; }()
985   );
986 };
987 
988 class Enclosing2 {
__anon1571c8ff7e02(auto x)989   void Method(char c = [](auto x)->char {
990     int d = []()->int {
991         struct LocalClass {
992           int Method() { return 0; }
993         };
994       return 0;
995     }();
996     return d; }(0)
997   );
998 };
999 
1000 class Enclosing3 {
__anon1571c8ff8002(auto x)1001   void Method(char c = [](auto x)->char {
1002     int d = [](auto y)->int {
1003         struct LocalClass {
1004           int Method() { return 0; }
1005         };
1006       return 0;
1007     }(0);
1008     return d; }(0)
1009   );
1010 };
1011 }
1012 
1013 namespace PR32638 {
1014  //https://bugs.llvm.org/show_bug.cgi?id=32638
test()1015  void test() {
1016     [](auto x) noexcept(noexcept(x)) { } (0);
1017  }
1018 }
1019 
1020 namespace PR46637 {
__anon1571c8ff8202(auto (*p)()) 1021   auto x = [](auto (*p)()) { return p(); };
__anon1571c8ff8302(auto (*p)() -> auto) 1022   auto y = [](auto (*p)() -> auto) { return p(); };
1023   int f();
1024   void *v = x(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
1025   void *w = y(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
1026 }
1027