/cp
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / lambda-generic-cfun.C
blobdd64d560cc01e9ee0810f322ddb676e659571cd2
1 // Generic lambda conversion to function ptr test from N3690 5.1.2.6
2 // { dg-do compile { target c++14 } }
3 // { dg-options "" }
5 void f1(int (*)(int)) { }
6 void f2(char (*)(int)) { }
7 void g(int (*)(int)) { } // #1
8 void g(char (*)(char)) { } // #2
9 void h(int (*)(int)) { } // #3
10 void h(char (*)(int)) { } // #4
12 int main()
14   auto glambda = [](auto a) { return a; };
15   int (*fp)(int) = glambda;
16   f1(glambda); // OK
17   f2(glambda); // { dg-error "invalid user-defined conversion" }
18   g(glambda); // { dg-error "ambiguous" }
19   h(glambda); // OK: calls #3 since it is convertible from ID
20   int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
22   auto GL = [](auto a) { return a; };
23   int (*GL_int)(int) = GL; // OK: through conversion function template
24   GL_int(3);