diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2024-09-16 22:04:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-16 22:04:06 +0100 |
| commit | 7caa3d9da71c38665340247a1c2bf9bedb8db925 (patch) | |
| tree | dcb7637f26db5363d0bdc3c60fd05660f8a371fd /test/behavior/pointers.zig | |
| parent | f3445f8f6935b4532aab3f339f5d86319d2dca72 (diff) | |
| parent | 7f60d2e4658ad78839ce0fce63a95dbcb893a256 (diff) | |
| download | zig-7caa3d9da71c38665340247a1c2bf9bedb8db925.tar.gz zig-7caa3d9da71c38665340247a1c2bf9bedb8db925.zip | |
Merge pull request #21425 from mlugg/pointer-arith-inplace-res-ty
compiler: provide correct result types to `+=` and `-=`
Diffstat (limited to 'test/behavior/pointers.zig')
| -rw-r--r-- | test/behavior/pointers.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 07041e70a1..bf0d37cc2b 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -98,6 +98,21 @@ test "pointer subtraction" { } } +test "pointer arithmetic with non-trivial RHS" { + var t: bool = undefined; + t = true; + + var ptr: [*]const u8 = "Hello, World!"; + ptr += if (t) 5 else 2; + try expect(ptr[0] == ','); + ptr += if (!t) 4 else 2; + try expect(ptr[0] == 'W'); + ptr -= if (t) @as(usize, 6) else 3; + try expect(ptr[0] == 'e'); + ptr -= if (!t) @as(usize, 0) else 1; + try expect(ptr[0] == 'H'); +} + test "double pointer parsing" { comptime assert(PtrOf(PtrOf(i32)) == **i32); } |
