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
6template<class F, class ...Rest> struct first_impl { typedef F type; };
7template<class ...Args> using first = typename first_impl<Args...>::type;
8
9namespace simple_explicit_capture {
10  void test() {
11    int i;
12    auto L = [i](auto a) { return i + a; };
13    L(3.14);
14  }
15}
16
17namespace explicit_call {
18int 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
26namespace test_conversion_to_fptr_2 {
27
28template<class T> struct X {
29
30  T (*fp)(T) = [](auto a) { return a; };
31
32};
33
34X<int> xi;
35
36template<class T>
37void fooT(T t, T (*fp)(T) = [](auto a) { return a; }) {
38  fp(t);
39}
40
41int 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}
123int run2 = test();
124
125}
126
127
128namespace test_conversion_to_fptr {
129
130void f1(int (*)(int)) { }
131void f2(char (*)(int)) { } // expected-note{{candidate}}
132void g(int (*)(int)) { } // #1 expected-note{{candidate}}
133void g(char (*)(char)) { } // #2 expected-note{{candidate}}
134void h(int (*)(int)) { } // #3
135void h(char (*)(int)) { } // #4
136
137int 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
175namespace more_converion_to_ptr_to_function_tests {
176
177
178int 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
195template<class ... Ts> void vfun(Ts ... ) { }
196
197int 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
209namespace conversion_operator {
210void 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
220namespace return_type_deduction_ok {
221 auto l = [](auto a) ->auto { return a; }(2);
222 auto l2 = [](auto a) ->decltype(auto) { return a; }(2);
223 auto l3 = [](auto a) { return a; }(2);
224
225}
226
227namespace generic_lambda_as_default_argument_ok {
228  void test(int i = [](auto a)->int { return a; }(3)) {
229  }
230}
231
232namespace nested_non_capturing_lambda_tests {
233template<class ... Ts> void print(Ts ...) { }
234int 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};
379X x;
380x.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
455namespace wrapped_within_templates {
456
457namespace explicit_return {
458template<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
476int run = fooT('a') + fooT(3.14);
477
478} // end explicit_return
479
480namespace implicit_return_deduction {
481template<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
499int run = fooT('a') + fooT(3.14);
500
501template<class ... Ts> void print(Ts ... ts) { }
502
503template<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
524int 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
531namespace at_ns_scope {
532  void foo(double d) { }
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  }
555auto L = test();
556auto L_test = L('4');
557auto M = L('3');
558auto M_test = M('a');
559auto N = M('x');
560auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
561char (*np)(const char*, int, const char*, double, const char*, int) = O;
562auto NP_result = np("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456);
563int (*np2)(const char*, int, const char*, double, const char*, int) = O; // expected-error{{no viable conversion}}
564
565
566
567}
568
569namespace variadic_tests_1 {
570template<class ... Ts> void print(Ts ... ts) { }
571
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(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
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(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
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
694namespace 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
736namespace 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
752namespace 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 ... Rest> F& FirstArg(F& f, Rest& ... r) { return f; };
775template<class ... Ts> auto vfun(Ts&& ... ts) {
776  print(ts...);
777  return FirstArg(ts...);
778}
779int 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}
793int run = test();
794}
795
796} // end ns nested_non_capturing_lambda_tests
797
798namespace PR17476 {
799struct string {
800  string(const char *__s) { }
801  string &operator+=(const string &__str) { return *this; }
802};
803
804template <class T>
805void finalizeDefaultAtomValues() {
806  auto startEnd = [](const char * sym) -> void {
807    string start("__");
808    start += sym;
809  };
810  startEnd("preinit_array");
811}
812
813void f() { finalizeDefaultAtomValues<char>(); }
814
815}
816
817namespace PR17476_variant {
818struct string {
819  string(const char *__s) { }
820  string &operator+=(const string &__str) { return *this; }
821};
822
823template <class T>
824void finalizeDefaultAtomValues() {
825  auto startEnd = [](const T *sym) -> void {
826    string start("__");
827    start += sym;
828  };
829  startEnd("preinit_array");
830}
831
832void f() { finalizeDefaultAtomValues<char>(); }
833
834}
835
836namespace PR17877_lambda_declcontext_and_get_cur_lambda_disconnect {
837
838
839template<class T> struct U {
840  int t = 0;
841};
842
843template<class T>
844struct V {
845  U<T> size() const { return U<T>{}; }
846};
847
848template<typename T>
849void Do() {
850  V<int> v{};
851  [=] { v.size(); };
852}
853
854}
855
856namespace inclass_lambdas_within_nested_classes {
857namespace ns1 {
858
859struct X1 {
860  struct X2 {
861    enum { E = [](auto i) { return i; }(3) }; //expected-error{{inside of a constant expression}}\
862                                          //expected-error{{not an integral constant}}
863    int L = ([] (int i) { return i; })(2);
864    void foo(int i = ([] (int i) { return i; })(2)) { }
865    int B : ([](int i) { return i; })(3); //expected-error{{inside of a constant expression}}\
866                                          //expected-error{{not an integral constant}}
867    int arr[([](int i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
868                                           //expected-error{{must have a constant size}}
869    int (*fp)(int) = [](int i) { return i; };
870    void fooptr(int (*fp)(char) = [](char c) { return 0; }) { }
871    int L2 = ([](auto i) { return i; })(2);
872    void fooG(int i = ([] (auto i) { return i; })(2)) { }
873    int BG : ([](auto i) { return i; })(3); //expected-error{{inside of a constant expression}}  \
874                                             //expected-error{{not an integral constant}}
875    int arrG[([](auto i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
876                                           //expected-error{{must have a constant size}}
877    int (*fpG)(int) = [](auto i) { return i; };
878    void fooptrG(int (*fp)(char) = [](auto c) { return 0; }) { }
879  };
880};
881} //end ns
882
883namespace ns2 {
884struct X1 {
885  template<class T>
886  struct X2 {
887    int L = ([] (T i) { return i; })(2);
888    void foo(int i = ([] (int i) { return i; })(2)) { }
889    int B : ([](T i) { return i; })(3); //expected-error{{inside of a constant expression}}\
890                                          //expected-error{{not an integral constant}}
891    int arr[([](T i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
892                                           //expected-error{{must have a constant size}}
893    int (*fp)(T) = [](T i) { return i; };
894    void fooptr(T (*fp)(char) = [](char c) { return 0; }) { }
895    int L2 = ([](auto i) { return i; })(2);
896    void fooG(T i = ([] (auto i) { return i; })(2)) { }
897    int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}
898    int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}}
899    int (*fpG)(T) = [](auto i) { return i; };
900    void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }
901    template<class U = char> int fooG2(T (*fp)(U) = [](auto a) { return 0; }) { return 0; }
902    template<class U = char> int fooG3(T (*fp)(U) = [](auto a) { return 0; });
903  };
904};
905template<class T>
906template<class U>
907int X1::X2<T>::fooG3(T (*fp)(U)) { return 0; }
908X1::X2<int> x2; //expected-note 3{{in instantiation of}}
909int run1 = x2.fooG2();
910int run2 = x2.fooG3();
911} // end ns
912
913
914
915} //end ns inclass_lambdas_within_nested_classes
916