| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=dip1000 -de |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/cast_qual.d(17): Deprecation: using the result of a cast from `const(int)` to `int` as an lvalue will become `@system` in a future release |
| 6 |
fail_compilation/cast_qual.d(19): Deprecation: using the result of a cast from `const(int)` to `int` as an lvalue will become `@system` in a future release |
| 7 |
fail_compilation/cast_qual.d(25): Error: cast from `const(Object)` to `object.Object` is not allowed in a `@safe` function |
| 8 |
fail_compilation/cast_qual.d(25): Incompatible type qualifier |
| 9 |
--- |
| 10 |
*/ |
| 11 |
|
| 12 |
@safe: |
| 13 |
|
| 14 |
void main() { |
| 15 |
const int i = 3; |
| 16 |
int j = cast() i; // OK |
| 17 |
int* p = &cast() i; // this should not compile in @safe code |
| 18 |
*p = 4; // oops |
| 19 |
cast() i = 5; // NG |
| 20 |
auto q = &cast(const) j; // OK, int* to const int* |
| 21 |
} |
| 22 |
|
| 23 |
void test() { |
| 24 |
const Object co; |
| 25 |
auto o = cast() co; |
| 26 |
} |