P0428R2 - familiar template syntax for generic lambdas
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / lambda-generic-dep.C
blob982a155e777b7987e193d186794d92073d44a394
1 // Generic lambda type dependence test part from N3690 5.1.2.12
2 // { dg-do compile { target c++14 } }
3 // { dg-options "-pedantic" }
5 void f(int, const int (&)[2] = {}) { } // #1
6 void f(const int&, const int (&)[1]) { } // #2
8 void test()
10   const int x = 17;
11   auto g = [](auto a) {
12     f(x); // OK: calls #1, does not capture x
13   };
14   auto g2 = [=](auto a) {
15     int selector[sizeof(a) == 1 ? 1 : 2]{};
16     f(x, selector); // OK: is a dependent expression, so captures x
17   };
20 struct S {
21   struct N {
22     auto test () { return 7.f; }
23   };
26 #include <utility>
28 int main()
30   auto f = [] <typename T> (T const& s) mutable {       // { dg-warning "lambda templates are only available with" "" { target c++17_down } }
31     typename T::N x;
32     return x.test ();
33   };
34   auto g = [] (auto const& s) {
35     typename std::decay<decltype (s)>::type::N x;
36     return x.test ();
37   };
39   S i;
40   f(i);
41   g(i);