zig/test/cases/compile_errors/reference_to_const_data.zig
Alex Rønne Petersen 2e3fac3626
test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00

35 lines
688 B
Zig

export fn foo() void {
var ptr = &[_]u8{ 0, 0, 0, 0 };
ptr[1] = 2;
}
export fn bar() void {
var ptr = &@as(u32, 2);
ptr.* = 2;
_ = &ptr;
}
export fn baz() void {
var ptr = &true;
ptr.* = false;
_ = &ptr;
}
export fn qux() void {
const S = struct {
x: usize,
y: usize,
};
var ptr = &S{ .x = 1, .y = 2 };
ptr.x = 2;
}
export fn quux() void {
var x = &@returnAddress();
x.* = 6;
_ = &x;
}
// error
//
// :3:8: error: cannot assign to constant
// :7:8: error: cannot assign to constant
// :12:8: error: cannot assign to constant
// :21:8: error: cannot assign to constant
// :25:6: error: cannot assign to constant