| 1 |
// Explicit generic lambda conversion to function ptr test from N3690 5.1.2.6 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
// { dg-options "" } |
| 4 |
|
| 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 |
| 11 |
|
| 12 |
int main() |
| 13 |
{ |
| 14 |
auto glambda = [] <typename T> (T 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*) = [] <typename T> (T* a) -> auto& { return *a; }; // OK |
| 21 |
|
| 22 |
auto GL = [] <typename T> (T a) { return a; }; |
| 23 |
int (*GL_int)(int) = GL; // OK: through conversion function template |
| 24 |
GL_int(3); |
| 25 |
} |
| 26 |
|