dmd/compiler/test/fail_compilation/system_ptr_cast.d

25 lines
634 B
D

/*
REQUIRED_ARGS: -preview=dip1000 -de
TEST_OUTPUT:
---
fail_compilation/system_ptr_cast.d(20): Deprecation: cast from `S*` to `int*` not allowed in safe code
fail_compilation/system_ptr_cast.d(20): Source element type has unsafe bit patterns and target element type is mutable
fail_compilation/system_ptr_cast.d(24): Deprecation: cast from `int*` to `S*` not allowed in safe code
fail_compilation/system_ptr_cast.d(24): Target element type has unsafe bit patterns
---
*/
struct S
{
@system int i;
}
void main() @safe
{
S s;
auto p = cast(int*) &s;
*p = 8;
int i = 8;
auto ps = cast(S*) &i;
}