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