| 1 |
// https://bugzilla.gdcproject.org/show_bug.cgi?id=35 |
| 2 |
// { dg-do run } |
| 3 |
// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } |
| 4 |
|
| 5 |
/** |
| 6 |
* Here the BinaryHeap instance uses an alias parameter and therefore |
| 7 |
* the instance's functions (percolateDown) need to be generated in |
| 8 |
* topNIndex->BinaryHeap scope and not in the declaration scope |
| 9 |
* (module->BinaryHeap). |
| 10 |
*/ |
| 11 |
void topNIndex()() |
| 12 |
{ |
| 13 |
bool indirectLess(int a, int b) |
| 14 |
{ |
| 15 |
return a > b; |
| 16 |
} |
| 17 |
|
| 18 |
auto a = BinaryHeap!(indirectLess)(); |
| 19 |
} |
| 20 |
|
| 21 |
struct BinaryHeap(alias less) |
| 22 |
{ |
| 23 |
void percolateDown() |
| 24 |
{ |
| 25 |
less(0, 1); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
void test35a() |
| 30 |
{ |
| 31 |
topNIndex(); |
| 32 |
} |
| 33 |
|
| 34 |
/* |
| 35 |
* Similar as test35a but with an additional indirection. |
| 36 |
* The nested function chain for percolateDown should look like this: |
| 37 |
* topNIndex2->BinaryHeap2->percolateDown. |
| 38 |
*/ |
| 39 |
void topNIndex2()() |
| 40 |
{ |
| 41 |
bool indirectLess(int a, int b) |
| 42 |
{ |
| 43 |
return a > b; |
| 44 |
} |
| 45 |
auto a = BinaryHeap2!(S35b!(indirectLess)())(); |
| 46 |
} |
| 47 |
|
| 48 |
struct S35b(alias a) |
| 49 |
{ |
| 50 |
void foo() |
| 51 |
{ |
| 52 |
a(0, 0); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
struct BinaryHeap2(alias less) |
| 57 |
{ |
| 58 |
void percolateDown() |
| 59 |
{ |
| 60 |
less.foo(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void test35b() |
| 65 |
{ |
| 66 |
topNIndex2(); |
| 67 |
} |
| 68 |
|
| 69 |
void main() |
| 70 |
{ |
| 71 |
test35a(); |
| 72 |
test35b(); |
| 73 |
} |