p3-generic-lambda-1y.cpp revision fad9e13f3cb85198f0ee5af620ba81cd78574faa
19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall//FIXME: These tests were written when return type deduction had not been implemented 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// for generic lambdas, hence 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltemplate<class T> T id(T t); 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltemplate<class ... Ts> int vfoo(Ts&& ... ts); 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallauto GL1 = [](auto a, int i) -> int { return id(a); }; 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallauto GL2 = [](auto ... As) -> int { return vfoo(As...); }; 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallauto GL3 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); }; 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallauto GL4 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); }; 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid foo() { 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto GL1 = [](auto a, int i) -> int { return id(a); }; 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto GL2 = [](auto ... As) -> int { return vfoo(As...); }; 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main() 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l1 = [](auto a) -> int { return a + 5; }; 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l2 = [](auto *p) -> int { return p + 5; }; 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct A { int i; char f(int) { return 'c'; } }; 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l3 = [](auto &&ur, 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto &lr, 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto v, 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i, 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto* p, 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto A::*memvar, 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto (A::*memfun)(int), 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char c, 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall decltype (v)* pv 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall , auto (&array)[5] 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ) -> int { return v + i + c 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + array[0]; 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall }; 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int arr[5] = {0, 1, 2, 3, 4 }; 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int lval = 0; 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall double d = 3.14; 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall l3(3, lval, d, lval, &lval, &A::i, &A::f, 'c', &d, arr); 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l4 = [](decltype(auto) a) -> int { return 0; }; //expected-error{{decltype(auto)}} 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct Local { 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int ifi(int i) { return i; } 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static char cfi(int) { return 'a'; } 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static double dfi(int i) { return i + 3.14; } 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static Local localfi(int) { return Local{}; } 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall }; 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l4 = [](auto (*fp)(int)) -> int { return fp(3); }; //expected-error{{no viable conversion from 'Local' to 'int'}} 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall l4(&Local::ifi); 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall l4(&Local::cfi); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall l4(&Local::dfi); 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall l4(&Local::localfi); //expected-note{{in instantiation of function template specialization}} 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto unnamed_parameter = [](auto, auto) -> void { }; 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unnamed_parameter(3, '4'); 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l = [](auto 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (*)(auto)) { }; //expected-error{{'auto' not allowed}} 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall //FIXME: These diagnostics might need some work. 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l2 = [](char auto::*pm) { }; //expected-error{{cannot combine with previous}}\ 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall expected-error{{'pm' does not point into a class}} 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall auto l3 = [](char (auto::*pmf)()) { }; //expected-error{{'auto' not allowed}}\ 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall expected-error{{'pmf' does not point into a class}}\ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall expected-error{{function cannot return function type 'char ()'}} 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall