p3-generic-lambda-1y.cpp revision ecb5819a9e64fb654d46a3b270a286cc570c58ff
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y
2
3//FIXME: These tests were written when return type deduction had not been implemented
4// for generic lambdas, hence
5template<class T> T id(T t);
6template<class ... Ts> int vfoo(Ts&& ... ts);
7auto GL1 = [](auto a, int i) -> int { return id(a); };
8
9auto GL2 = [](auto ... As) -> int { return vfoo(As...); };
10auto GL3 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); };
11
12auto GL4 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); };
13
14
15void foo() {
16  auto GL1 = [](auto a, int i) -> int { return id(a); };
17
18  auto GL2 = [](auto ... As) -> int { return vfoo(As...); };
19}
20
21
22int main()
23{
24  auto l1 = [](auto a) -> int { return a + 5; };
25  auto l2 = [](auto *p) -> int { return p + 5; };
26
27  struct A { int i; char f(int) { return 'c'; } };
28  auto l3 = [](auto &&ur,
29                auto &lr,
30                auto v,
31                int i,
32                auto* p,
33                auto A::*memvar,
34                auto (A::*memfun)(int),
35                char c,
36                decltype (v)* pv
37                , auto (&array)[5]
38              ) -> int { return v + i + c
39                          + array[0];
40                       };
41  int arr[5] = {0, 1, 2, 3, 4 };
42  int lval = 0;
43  double d = 3.14;
44  l3(3, lval, d, lval, &lval, &A::i, &A::f, 'c', &d, arr);
45  auto l4 = [](decltype(auto) a) -> int { return 0; }; //expected-error{{decltype(auto)}}
46  {
47    struct Local {
48      static int ifi(int i) { return i; }
49      static char cfi(int) { return 'a'; }
50      static double dfi(int i) { return i + 3.14; }
51      static Local localfi(int) { return Local{}; }
52    };
53    auto l4 = [](auto (*fp)(int)) -> int { return fp(3); }; //expected-error{{no viable conversion from 'Local' to 'int'}}
54    l4(&Local::ifi);
55    l4(&Local::cfi);
56    l4(&Local::dfi);
57    l4(&Local::localfi); //expected-note{{in instantiation of function template specialization}}
58  }
59  {
60    auto unnamed_parameter = [](auto, auto) -> void { };
61    unnamed_parameter(3, '4');
62  }
63  {
64    auto l = [](auto
65                      (*)(auto)) { }; //expected-error{{'auto' not allowed}}
66    //FIXME: These diagnostics might need some work.
67    auto l2 = [](char auto::*pm) { };  //expected-error{{cannot combine with previous}}\
68                                         expected-error{{'pm' does not point into a class}}
69    auto l3 = [](char (auto::*pmf)()) { };  //expected-error{{'auto' not allowed}}\
70                                              expected-error{{'pmf' does not point into a class}}\
71                                              expected-error{{function cannot return function type 'char ()'}}
72  }
73}
74
75
76