| 1 |
// https://issues.dlang.org/show_bug.cgi?id=16635 |
| 2 |
|
| 3 |
struct A |
| 4 |
{ |
| 5 |
alias get this; |
| 6 |
|
| 7 |
const(A) get() const |
| 8 |
{ |
| 9 |
return A(); |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
static assert(!__traits(compiles, A() + A())); |
| 14 |
|
| 15 |
// Original test (covers another path) |
| 16 |
|
| 17 |
struct Vector2 |
| 18 |
{ |
| 19 |
float x; |
| 20 |
float y; |
| 21 |
|
| 22 |
alias byRef this; |
| 23 |
|
| 24 |
ref const(Vector2) byRef() const |
| 25 |
{ |
| 26 |
static Vector2 v; |
| 27 |
return v; |
| 28 |
} |
| 29 |
|
| 30 |
Vector2 opBinary(string op : "+")(ref const(Vector2) a) const |
| 31 |
{ |
| 32 |
return Vector2(x + a.x, y + a.y); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
void test16635_1() |
| 37 |
{ |
| 38 |
Vector2 a = Vector2(1, 2); |
| 39 |
Vector2 b = Vector2(3, 4); |
| 40 |
|
| 41 |
// this line causes application to run infinitely |
| 42 |
// Already fixed. It was https://issues.dlang.org/show_bug.cgi?id=16621 |
| 43 |
Vector2 c = a + b; |
| 44 |
|
| 45 |
// OK <- this line seg faults without the above line |
| 46 |
Vector2 d = a + Vector2(5, 6); |
| 47 |
} |
| 48 |
|
| 49 |
void test16635_2() |
| 50 |
{ |
| 51 |
Vector2 a = Vector2(1, 2); |
| 52 |
Vector2 b = Vector2(3, 4); |
| 53 |
|
| 54 |
// just this line alone |
| 55 |
Vector2 d = a + Vector2(5, 6); |
| 56 |
} |