| 1 |
/* PERMUTE_ARGS: -O -inline |
| 2 |
*/ |
| 3 |
// https://issues.dlang.org/show_bug.cgi?id=22115 |
| 4 |
|
| 5 |
|
| 6 |
int sx; |
| 7 |
void sss() { ++sx; } |
| 8 |
|
| 9 |
static if (1) |
| 10 |
{ |
| 11 |
struct S { int a; } |
| 12 |
|
| 13 |
void test1(S* s) |
| 14 |
{ |
| 15 |
if (s.a == 3 ? s : null) |
| 16 |
sss(); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
static if (1) |
| 21 |
{ |
| 22 |
extern (C++) class Exp |
| 23 |
{ |
| 24 |
int a; |
| 25 |
|
| 26 |
void func() { } |
| 27 |
final inout(AddExp) isAddExp() inout { return a == 3 ? cast(typeof(return))this : null; } |
| 28 |
} |
| 29 |
|
| 30 |
extern (C++) class AddExp : Exp |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
void test2(Exp e) |
| 35 |
{ |
| 36 |
if (e.isAddExp()) |
| 37 |
sss(); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
int main() |
| 43 |
{ |
| 44 |
static if (1) |
| 45 |
{ |
| 46 |
S s; |
| 47 |
s.a = 3; |
| 48 |
test1(&s); |
| 49 |
assert(sx == 1); |
| 50 |
s.a = 2; |
| 51 |
test1(&s); |
| 52 |
assert(sx == 1); |
| 53 |
} |
| 54 |
sx = 1; |
| 55 |
|
| 56 |
static if (1) |
| 57 |
{ |
| 58 |
auto c = new AddExp(); |
| 59 |
c.a = 3; |
| 60 |
test2(c); |
| 61 |
assert(sx == 2); |
| 62 |
auto ae = c.isAddExp(); |
| 63 |
assert(ae && ae.a == 3); |
| 64 |
c.a = 2; |
| 65 |
test2(c); |
| 66 |
assert(sx == 2); |
| 67 |
} |
| 68 |
|
| 69 |
return 0; |
| 70 |
} |