| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/test13667.d(112): Error: cannot cast expression `this` of type `const(Array1!int)` to `Array1!int*` |
| 5 |
fail_compilation/test13667.d(116): Error: template instance `test13667.Array1!int` error instantiating |
| 6 |
fail_compilation/test13667.d(121): Error: cannot cast expression `this` of type `const(Array2!int)` to `B*` |
| 7 |
fail_compilation/test13667.d(125): Error: template instance `test13667.Array2!int` error instantiating |
| 8 |
fail_compilation/test13667.d(136): Error: cannot cast expression `this` of type `const(Array3!int)` to `C*` |
| 9 |
fail_compilation/test13667.d(140): Error: template instance `test13667.Array3!int` error instantiating |
| 10 |
fail_compilation/test13667.d(151): Error: cannot cast expression `this` of type `const(Array4!int)` to `D*` |
| 11 |
fail_compilation/test13667.d(155): Error: template instance `test13667.Array4!int` error instantiating |
| 12 |
fail_compilation/test13667.d(172): Error: cannot cast expression `this` of type `const(Array5!int)` to `F*` |
| 13 |
fail_compilation/test13667.d(176): Error: template instance `test13667.Array5!int` error instantiating |
| 14 |
--- |
| 15 |
*/ |
| 16 |
|
| 17 |
// https://issues.dlang.org/show_bug.cgi?id=13667 |
| 18 |
|
| 19 |
#line 100 |
| 20 |
// 0, no error but also crashed before |
| 21 |
struct Array0(T) |
| 22 |
{ |
| 23 |
Array0!(T) impConv() const { return cast(typeof(return))this; } |
| 24 |
alias impConv this; |
| 25 |
} |
| 26 |
|
| 27 |
alias AI0 = Array0!int; |
| 28 |
|
| 29 |
// 1 |
| 30 |
struct Array1(T) |
| 31 |
{ |
| 32 |
Array1!(T) impConv() const { return *cast(typeof(return)*)this; } |
| 33 |
alias impConv this; |
| 34 |
} |
| 35 |
|
| 36 |
alias AI1 = Array1!int; |
| 37 |
|
| 38 |
// 2 |
| 39 |
struct Array2(T) |
| 40 |
{ |
| 41 |
B impConv() const { return cast(B*)this; } |
| 42 |
alias impConv this; |
| 43 |
} |
| 44 |
|
| 45 |
alias AI2 = Array2!int; |
| 46 |
|
| 47 |
struct B |
| 48 |
{ |
| 49 |
AI2 get() { return AI2(); } |
| 50 |
alias get this; |
| 51 |
} |
| 52 |
|
| 53 |
// 3 |
| 54 |
struct Array3(T) |
| 55 |
{ |
| 56 |
C impConv() const { return cast(C*)this; } |
| 57 |
alias impConv this; |
| 58 |
} |
| 59 |
|
| 60 |
alias AI3 = Array3!int; |
| 61 |
|
| 62 |
struct C |
| 63 |
{ |
| 64 |
C get() { return C(); } |
| 65 |
alias get this; |
| 66 |
} |
| 67 |
|
| 68 |
// 4 |
| 69 |
struct Array4(T) |
| 70 |
{ |
| 71 |
D impConv() const { return cast(D*)this; } |
| 72 |
alias impConv this; |
| 73 |
} |
| 74 |
|
| 75 |
alias AI4 = Array4!int; |
| 76 |
|
| 77 |
struct D |
| 78 |
{ |
| 79 |
E get() { return E(); } |
| 80 |
alias get this; |
| 81 |
} |
| 82 |
|
| 83 |
struct E |
| 84 |
{ |
| 85 |
AI4 ai; |
| 86 |
alias ai this; |
| 87 |
} |
| 88 |
|
| 89 |
// 5: test enum based on struct, needed to use base type (toBasetype()) |
| 90 |
struct Array5(T) |
| 91 |
{ |
| 92 |
F impConv() const { return cast(F*)this; } |
| 93 |
alias impConv this; |
| 94 |
} |
| 95 |
|
| 96 |
alias AI5 = Array5!int; |
| 97 |
|
| 98 |
enum F : AI5 |
| 99 |
{ |
| 100 |
f = AI5() |
| 101 |
} |