aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/pointers.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2024-01-02 17:33:41 +0200
committerAndrew Kelley <andrew@ziglang.org>2024-01-06 16:49:41 -0800
commit804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc (patch)
tree3d8c534b1adc352b248255ef2906ef2bdf11dffc /test/behavior/pointers.zig
parent282ff8d3bd4a0d870a98f145aa87039e0409b745 (diff)
downloadzig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.tar.gz
zig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.zip
categorize `behavior/bugs/<issueno>.zig` tests
Diffstat (limited to 'test/behavior/pointers.zig')
-rw-r--r--test/behavior/pointers.zig65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig
index 3e3e67cc4e..68ff5b66f7 100644
--- a/test/behavior/pointers.zig
+++ b/test/behavior/pointers.zig
@@ -555,3 +555,68 @@ test "result type found through optional pointer" {
try expect(ptr2.?[0] == 123);
try expect(ptr2.?[1] == 0xCD);
}
+
+const Box0 = struct {
+ items: [4]Item,
+
+ const Item = struct {
+ num: u32,
+ };
+};
+const Box1 = struct {
+ items: [4]Item,
+
+ const Item = struct {};
+};
+const Box2 = struct {
+ items: [4]Item,
+
+ const Item = struct {
+ nothing: void,
+ };
+};
+
+fn mutable() !void {
+ var box0: Box0 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
+
+ var box1: Box1 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
+
+ var box2: Box2 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
+}
+
+fn constant() !void {
+ const box0: Box0 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
+
+ const box1: Box1 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
+
+ const box2: Box2 = .{ .items = undefined };
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
+}
+
+test "pointer-to-array constness for zero-size elements, var" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ try mutable();
+ try comptime mutable();
+}
+
+test "pointer-to-array constness for zero-size elements, const" {
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ try constant();
+ try comptime constant();
+}
+
+test "cast pointers with zero sized elements" {
+ const a: *void = undefined;
+ const b: *[1]void = a;
+ _ = b;
+ const c: *[0]u8 = undefined;
+ const d: []u8 = c;
+ _ = d;
+}