| 1 |
// https://issues.dlang.org/show_bug.cgi?id=21380 |
| 2 |
/* |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/test21380.d(39): Error: partial template instance `MySerializer().serializeSinkType!int` has no value |
| 6 |
fail_compilation/test21380.d(44): Error: template instance `test21380.SupportSinkTypeSer!(MySerializer!int)` error instantiating |
| 7 |
--- |
| 8 |
*/ |
| 9 |
|
| 10 |
template isSomeFunction(T...) |
| 11 |
if (T.length == 1) |
| 12 |
{ |
| 13 |
static if (is(typeof(& T[0]) U : U*) && is(U == function) || is(typeof(& T[0]) U == delegate)) |
| 14 |
{ |
| 15 |
// T is a (nested) function symbol. |
| 16 |
enum bool isSomeFunction = true; |
| 17 |
} |
| 18 |
else static if (is(T[0] W) || is(typeof(T[0]) W)) |
| 19 |
{ |
| 20 |
// T is an expression or a type. Take the type of it and examine. |
| 21 |
static if (is(W F : F*) && is(F == function)) |
| 22 |
enum bool isSomeFunction = true; // function pointer |
| 23 |
else |
| 24 |
enum bool isSomeFunction = is(W == function) || is(W == delegate); |
| 25 |
} |
| 26 |
else |
| 27 |
enum bool isSomeFunction = false; |
| 28 |
} |
| 29 |
|
| 30 |
struct MySerializer (T) |
| 31 |
{ |
| 32 |
void serializeSinkType(T2) (scope auto ref T2 record) {} |
| 33 |
} |
| 34 |
|
| 35 |
template SupportSinkTypeSer(SerT) |
| 36 |
{ |
| 37 |
/* Note: Partial template instance because it needs inference, in this case |
| 38 |
it cannot infer 'auto ref' parameter */ |
| 39 |
enum SupportSinkTypeSer = isSomeFunction!(SerT.init.serializeSinkType!int); |
| 40 |
} |
| 41 |
|
| 42 |
int main() |
| 43 |
{ |
| 44 |
enum x = SupportSinkTypeSer!(MySerializer!int); |
| 45 |
return 0; |
| 46 |
} |