| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail14304.d(26): Error: reinterpreting cast from `const(S14304)*` to `S14304*` is not supported in CTFE |
| 5 |
fail_compilation/fail14304.d(58): called from here: `sle14304.modify()` |
| 6 |
fail_compilation/fail14304.d(35): Error: cannot modify read-only constant `[1:1, 2:2]` |
| 7 |
fail_compilation/fail14304.d(61): called from here: `modify14304(aae14304)` |
| 8 |
fail_compilation/fail14304.d(41): Error: cannot modify read-only constant `[1, 2, 3]` |
| 9 |
fail_compilation/fail14304.d(64): called from here: `modify14304(cast(const(int)[])index14304)` |
| 10 |
fail_compilation/fail14304.d(46): Error: array cast from `immutable(double[])` to `double[]` is not supported at compile time |
| 11 |
fail_compilation/fail14304.d(67): called from here: `modify14304(cast(const(double)[])slice14304)` |
| 12 |
fail_compilation/fail14304.d(53): Error: cannot modify read-only string literal `"abc"` |
| 13 |
fail_compilation/fail14304.d(70): called from here: `modify14304(cast(const(char)[])str14304)` |
| 14 |
--- |
| 15 |
*/ |
| 16 |
|
| 17 |
struct S14304 |
| 18 |
{ |
| 19 |
int x; |
| 20 |
|
| 21 |
int modify() const |
| 22 |
{ |
| 23 |
assert(x == 1); |
| 24 |
|
| 25 |
// This force modification must not affect to ghe s14304 value. |
| 26 |
(cast(S14304*)&this).x = 10; |
| 27 |
|
| 28 |
assert(x == 10); |
| 29 |
return x; |
| 30 |
} |
| 31 |
} |
| 32 |
int modify14304(immutable int[int] aa) |
| 33 |
{ |
| 34 |
auto p = cast(int*)&aa[1]; |
| 35 |
*p = 10; |
| 36 |
return aa[1]; |
| 37 |
} |
| 38 |
int modify14304(const(int)[] arr) |
| 39 |
{ |
| 40 |
auto a = cast(int[])arr; |
| 41 |
a[0] = 10; |
| 42 |
return arr[0]; |
| 43 |
} |
| 44 |
int modify14304(const(double)[] arr) |
| 45 |
{ |
| 46 |
auto a = cast(double[])arr; |
| 47 |
a[] = 3.14; |
| 48 |
return cast(int)arr[0]; |
| 49 |
} |
| 50 |
int modify14304(const(char)[] str) |
| 51 |
{ |
| 52 |
auto s = cast(char[])str; |
| 53 |
s[0] = 'z'; |
| 54 |
return str[0]; |
| 55 |
} |
| 56 |
|
| 57 |
static immutable sle14304 = immutable S14304(1); |
| 58 |
static immutable v14304 = sle14304.modify(); |
| 59 |
|
| 60 |
static immutable aae14304 = [1:1, 2:2]; |
| 61 |
static immutable w14304 = modify14304(aae14304); |
| 62 |
|
| 63 |
static immutable index14304 = [1, 2, 3]; |
| 64 |
static immutable x14304 = modify14304(index14304); |
| 65 |
|
| 66 |
static immutable slice14304 = [1.414, 1.732, 2]; |
| 67 |
static immutable y14304 = modify14304(slice14304); |
| 68 |
|
| 69 |
static immutable str14304 = "abc"; |
| 70 |
static immutable z14304 = modify14304(str14304); |