| 1 |
/* |
| 2 |
REQUIRED_ARGS: -de -preview=dip1000 |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/bool_cast.d(17): Deprecation: cast from `ubyte[]` to `bool[]` will become `@system` in a future release |
| 6 |
fail_compilation/bool_cast.d(17): Source element may have bytes which are not 0 or 1 |
| 7 |
fail_compilation/bool_cast.d(22): Deprecation: cast from `int*` to `bool*` will become `@system` in a future release |
| 8 |
fail_compilation/bool_cast.d(22): Source element may have bytes which are not 0 or 1 |
| 9 |
fail_compilation/bool_cast.d(24): Deprecation: cast from `bool*` to `byte*` will become `@system` in a future release |
| 10 |
fail_compilation/bool_cast.d(24): Target element could be assigned a byte which is not 0 or 1 |
| 11 |
--- |
| 12 |
*/ |
| 13 |
|
| 14 |
void main() @safe |
| 15 |
{ |
| 16 |
ubyte[] a = [2, 4]; |
| 17 |
auto b = cast(bool[]) a; // reinterprets a's data |
| 18 |
auto c = cast(bool[]) [2, 4]; // OK, literal cast applies to each element |
| 19 |
auto d = cast(const(byte)[]) b; // OK, result's elements are const |
| 20 |
|
| 21 |
int i = 2; |
| 22 |
auto p = cast(bool*) &i; |
| 23 |
bool v; |
| 24 |
auto bp = cast(byte*) &v; |
| 25 |
*bp = 2; // v is now invalid |
| 26 |
} |