aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/pointer_exceeds_containing_value.zig
blob: d9e9376848d45a633b89ca9a0935b83604554b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export fn entry1() void {
    const x: u32 = 123;
    const ptr: [*]const u32 = @ptrCast(&x);
    _ = ptr - 1;
}

export fn entry2() void {
    const S = extern struct { x: u32, y: u32 };
    const y: u32 = 123;
    const parent_ptr: *const S = @fieldParentPtr("y", &y);
    _ = parent_ptr;
}

// error
//
// :4:13: error: pointer computation here causes undefined behavior
// :4:13: note: resulting pointer exceeds bounds of containing value which may trigger overflow
// :10:55: error: pointer computation here causes undefined behavior
// :10:55: note: resulting pointer exceeds bounds of containing value which may trigger overflow