aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/pointers.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2024-09-16 22:04:06 +0100
committerGitHub <noreply@github.com>2024-09-16 22:04:06 +0100
commit7caa3d9da71c38665340247a1c2bf9bedb8db925 (patch)
treedcb7637f26db5363d0bdc3c60fd05660f8a371fd /test/behavior/pointers.zig
parentf3445f8f6935b4532aab3f339f5d86319d2dca72 (diff)
parent7f60d2e4658ad78839ce0fce63a95dbcb893a256 (diff)
downloadzig-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.zig15
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);
}