authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-16 13:21:18+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:57:03+00:00
log9c16b2370d30e74a63a84a835d840266021424fd
tree9447b9b05beb2e181d8fba96fd28b333d41792c4
parent21fa187abc2a06c9bd5cfe4355c5edbfb3177f6b
signature Commit is signed but in an unrecognized format.

test: update behavior to silence 'var is never mutated' errors


104 files changed, 1160 insertions(+), 390 deletions(-)

test/behavior/abs.zig+33
...@@ -16,26 +16,32 @@ test "@abs integers" {...@@ -16,26 +16,32 @@ test "@abs integers" {
16fn testAbsIntegers() !void {16fn testAbsIntegers() !void {
17 {17 {
18 var x: i32 = -1000;18 var x: i32 = -1000;
19 _ = &x;
19 try expect(@abs(x) == 1000);20 try expect(@abs(x) == 1000);
20 }21 }
21 {22 {
22 var x: i32 = 0;23 var x: i32 = 0;
24 _ = &x;
23 try expect(@abs(x) == 0);25 try expect(@abs(x) == 0);
24 }26 }
25 {27 {
26 var x: i32 = 1000;28 var x: i32 = 1000;
29 _ = &x;
27 try expect(@abs(x) == 1000);30 try expect(@abs(x) == 1000);
28 }31 }
29 {32 {
30 var x: i64 = std.math.minInt(i64);33 var x: i64 = std.math.minInt(i64);
34 _ = &x;
31 try expect(@abs(x) == @as(u64, -std.math.minInt(i64)));35 try expect(@abs(x) == @as(u64, -std.math.minInt(i64)));
32 }36 }
33 {37 {
34 var x: i5 = -1;38 var x: i5 = -1;
39 _ = &x;
35 try expect(@abs(x) == 1);40 try expect(@abs(x) == 1);
36 }41 }
37 {42 {
38 var x: i5 = -5;43 var x: i5 = -5;
44 _ = &x;
39 try expect(@abs(x) == 5);45 try expect(@abs(x) == 5);
40 }46 }
41 comptime {47 comptime {
...@@ -56,22 +62,27 @@ test "@abs unsigned integers" {...@@ -56,22 +62,27 @@ test "@abs unsigned integers" {
56fn testAbsUnsignedIntegers() !void {62fn testAbsUnsignedIntegers() !void {
57 {63 {
58 var x: u32 = 1000;64 var x: u32 = 1000;
65 _ = &x;
59 try expect(@abs(x) == 1000);66 try expect(@abs(x) == 1000);
60 }67 }
61 {68 {
62 var x: u32 = 0;69 var x: u32 = 0;
70 _ = &x;
63 try expect(@abs(x) == 0);71 try expect(@abs(x) == 0);
64 }72 }
65 {73 {
66 var x: u32 = 1000;74 var x: u32 = 1000;
75 _ = &x;
67 try expect(@abs(x) == 1000);76 try expect(@abs(x) == 1000);
68 }77 }
69 {78 {
70 var x: u5 = 1;79 var x: u5 = 1;
80 _ = &x;
71 try expect(@abs(x) == 1);81 try expect(@abs(x) == 1);
72 }82 }
73 {83 {
74 var x: u5 = 5;84 var x: u5 = 5;
85 _ = &x;
75 try expect(@abs(x) == 5);86 try expect(@abs(x) == 5);
76 }87 }
77 comptime {88 comptime {
...@@ -102,27 +113,33 @@ test "@abs floats" {...@@ -102,27 +113,33 @@ test "@abs floats" {
102fn testAbsFloats(comptime T: type) !void {113fn testAbsFloats(comptime T: type) !void {
103 {114 {
104 var x: T = -2.62;115 var x: T = -2.62;
116 _ = &x;
105 try expect(@abs(x) == 2.62);117 try expect(@abs(x) == 2.62);
106 }118 }
107 {119 {
108 var x: T = 2.62;120 var x: T = 2.62;
121 _ = &x;
109 try expect(@abs(x) == 2.62);122 try expect(@abs(x) == 2.62);
110 }123 }
111 {124 {
112 var x: T = 0.0;125 var x: T = 0.0;
126 _ = &x;
113 try expect(@abs(x) == 0.0);127 try expect(@abs(x) == 0.0);
114 }128 }
115 {129 {
116 var x: T = -std.math.pi;130 var x: T = -std.math.pi;
131 _ = &x;
117 try expect(@abs(x) == std.math.pi);132 try expect(@abs(x) == std.math.pi);
118 }133 }
119134
120 {135 {
121 var x: T = -std.math.inf(T);136 var x: T = -std.math.inf(T);
137 _ = &x;
122 try expect(@abs(x) == std.math.inf(T));138 try expect(@abs(x) == std.math.inf(T));
123 }139 }
124 {140 {
125 var x: T = std.math.inf(T);141 var x: T = std.math.inf(T);
142 _ = &x;
126 try expect(@abs(x) == std.math.inf(T));143 try expect(@abs(x) == std.math.inf(T));
127 }144 }
128 comptime {145 comptime {
...@@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void {...@@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void {
164 {181 {
165 var x: I32 = @splat(-10);182 var x: I32 = @splat(-10);
166 var y: U32 = @splat(10);183 var y: U32 = @splat(10);
184 _ = .{ &x, &y };
167 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));185 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
168 }186 }
169 {187 {
170 var x: I32 = @splat(10);188 var x: I32 = @splat(10);
171 var y: U32 = @splat(10);189 var y: U32 = @splat(10);
190 _ = .{ &x, &y };
172 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));191 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
173 }192 }
174 {193 {
175 var x: I32 = @splat(0);194 var x: I32 = @splat(0);
176 var y: U32 = @splat(0);195 var y: U32 = @splat(0);
196 _ = .{ &x, &y };
177 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));197 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
178 }198 }
179 {199 {
180 var x: I64 = @splat(-10);200 var x: I64 = @splat(-10);
181 var y: U64 = @splat(10);201 var y: U64 = @splat(10);
202 _ = .{ &x, &y };
182 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));203 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
183 }204 }
184 {205 {
185 var x: I64 = @splat(std.math.minInt(i64));206 var x: I64 = @splat(std.math.minInt(i64));
186 var y: U64 = @splat(-std.math.minInt(i64));207 var y: U64 = @splat(-std.math.minInt(i64));
208 _ = .{ &x, &y };
187 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));209 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
188 }210 }
189 {211 {
190 var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 });212 var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 });
191 var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 });213 var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 });
214 _ = .{ &x, &y };
192 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));215 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
193 }216 }
194}217}
...@@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void {...@@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void {
225 {248 {
226 var x: U32 = @splat(10);249 var x: U32 = @splat(10);
227 var y: U32 = @splat(10);250 var y: U32 = @splat(10);
251 _ = .{ &x, &y };
228 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));252 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
229 }253 }
230 {254 {
231 var x: U32 = @splat(10);255 var x: U32 = @splat(10);
232 var y: U32 = @splat(10);256 var y: U32 = @splat(10);
257 _ = .{ &x, &y };
233 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));258 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
234 }259 }
235 {260 {
236 var x: U32 = @splat(0);261 var x: U32 = @splat(0);
237 var y: U32 = @splat(0);262 var y: U32 = @splat(0);
263 _ = .{ &x, &y };
238 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));264 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
239 }265 }
240 {266 {
241 var x: U64 = @splat(10);267 var x: U64 = @splat(10);
242 var y: U64 = @splat(10);268 var y: U64 = @splat(10);
269 _ = .{ &x, &y };
243 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));270 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
244 }271 }
245 {272 {
246 var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });273 var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });
247 var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });274 var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });
275 _ = .{ &x, &y };
248 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));276 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
249 }277 }
250}278}
...@@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void {...@@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void {
346 {374 {
347 var x: V = @splat(-7.5);375 var x: V = @splat(-7.5);
348 var y: V = @splat(7.5);376 var y: V = @splat(7.5);
377 _ = .{ &x, &y };
349 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));378 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
350 }379 }
351 {380 {
352 var x: V = @splat(7.5);381 var x: V = @splat(7.5);
353 var y: V = @splat(7.5);382 var y: V = @splat(7.5);
383 _ = .{ &x, &y };
354 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));384 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
355 }385 }
356 {386 {
357 var x: V = @splat(0.0);387 var x: V = @splat(0.0);
358 var y: V = @splat(0.0);388 var y: V = @splat(0.0);
389 _ = .{ &x, &y };
359 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));390 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
360 }391 }
361 {392 {
362 var x: V = @splat(-std.math.pi);393 var x: V = @splat(-std.math.pi);
363 var y: V = @splat(std.math.pi);394 var y: V = @splat(std.math.pi);
395 _ = .{ &x, &y };
364 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));396 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
365 }397 }
366 {398 {
367 var x: V = @splat(std.math.pi);399 var x: V = @splat(std.math.pi);
368 var y: V = @splat(std.math.pi);400 var y: V = @splat(std.math.pi);
401 _ = .{ &x, &y };
369 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));402 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
370 }403 }
371}404}
test/behavior/align.zig+8-2
...@@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {...@@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3030
31 var runtime_index: usize = 1;31 var runtime_index: usize = 1;
32 _ = &runtime_index;
32 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];33 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
33 try expect(@TypeOf(slice) == []u8);34 try expect(@TypeOf(slice) == []u8);
34 try expect(slice.len == 0);35 try expect(slice.len == 0);
...@@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" {...@@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" {
438 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2439 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
439 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };440 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
440 var runtime_zero: usize = 0;441 var runtime_zero: usize = 0;
442 _ = &runtime_zero;
441 comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);443 comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
442 comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);444 comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
443 try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);445 try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
...@@ -464,6 +466,7 @@ test "alignment of function with c calling convention" {...@@ -464,6 +466,7 @@ test "alignment of function with c calling convention" {
464 const a = @alignOf(@TypeOf(nothing));466 const a = @alignOf(@TypeOf(nothing));
465467
466 var runtime_nothing = &nothing;468 var runtime_nothing = &nothing;
469 _ = &runtime_nothing;
467 const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);470 const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);
468 const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);471 const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);
469 casted2();472 casted2();
...@@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" {...@@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" {
486 .nevermind = 1,489 .nevermind = 1,
487 .badguy = 12,490 .badguy = 12,
488 };491 };
492 _ = &default_aligned;
489 try expect(12 == default_aligned.badguy);493 try expect(12 == default_aligned.badguy);
490}494}
491495
...@@ -579,10 +583,10 @@ test "comptime alloc alignment" {...@@ -579,10 +583,10 @@ test "comptime alloc alignment" {
579 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;583 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
580584
581 comptime var bytes1 = [_]u8{0};585 comptime var bytes1 = [_]u8{0};
582 _ = bytes1;586 _ = &bytes1;
583587
584 comptime var bytes2 align(256) = [_]u8{0};588 comptime var bytes2 align(256) = [_]u8{0};
585 var bytes2_addr = @intFromPtr(&bytes2);589 const bytes2_addr = @intFromPtr(&bytes2);
586 try expect(bytes2_addr & 0xff == 0);590 try expect(bytes2_addr & 0xff == 0);
587}591}
588592
...@@ -591,6 +595,7 @@ test "@alignCast null" {...@@ -591,6 +595,7 @@ test "@alignCast null" {
591 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO595 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
592596
593 var ptr: ?*anyopaque = null;597 var ptr: ?*anyopaque = null;
598 _ = &ptr;
594 const aligned: ?*anyopaque = @alignCast(ptr);599 const aligned: ?*anyopaque = @alignCast(ptr);
595 try expect(aligned == null);600 try expect(aligned == null);
596}601}
...@@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" {...@@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" {
637 var s32: S align(32) = .{};642 var s32: S align(32) = .{};
638643
639 var zero: usize = 0;644 var zero: usize = 0;
645 _ = &zero;
640646
641 try expect(@intFromPtr(&s) % @alignOf(usize) == 0);647 try expect(@intFromPtr(&s) % @alignOf(usize) == 0);
642 try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0);648 try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0);
test/behavior/alignof.zig+1
...@@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" {...@@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" {
31 var buf: [1024]u8 align(64) = undefined;31 var buf: [1024]u8 align(64) = undefined;
32 var start: usize = 1;32 var start: usize = 1;
33 var end: usize = undefined;33 var end: usize = undefined;
34 _ = .{ &start, &end };
34 try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8));35 try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8));
35 try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8));36 try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8));
36 try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8));37 try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8));
test/behavior/array.zig+26-7
...@@ -138,6 +138,7 @@ test "array literal with specified size" {...@@ -138,6 +138,7 @@ test "array literal with specified size" {
138 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO138 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
139139
140 var array = [2]u8{ 1, 2 };140 var array = [2]u8{ 1, 2 };
141 _ = &array;
141 try expect(array[0] == 1);142 try expect(array[0] == 1);
142 try expect(array[1] == 2);143 try expect(array[1] == 2);
143}144}
...@@ -146,7 +147,7 @@ test "array len field" {...@@ -146,7 +147,7 @@ test "array len field" {
146 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO147 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
147148
148 var arr = [4]u8{ 0, 0, 0, 0 };149 var arr = [4]u8{ 0, 0, 0, 0 };
149 var ptr = &arr;150 const ptr = &arr;
150 try expect(arr.len == 4);151 try expect(arr.len == 4);
151 try comptime expect(arr.len == 4);152 try comptime expect(arr.len == 4);
152 try expect(ptr.len == 4);153 try expect(ptr.len == 4);
...@@ -163,7 +164,8 @@ test "array with sentinels" {...@@ -163,7 +164,8 @@ test "array with sentinels" {
163 {164 {
164 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};165 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
165 try expect(zero_sized[0] == 0xde);166 try expect(zero_sized[0] == 0xde);
166 var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized));167 var reinterpreted: *[1]u8 = @ptrCast(&zero_sized);
168 _ = &reinterpreted;
167 try expect(reinterpreted[0] == 0xde);169 try expect(reinterpreted[0] == 0xde);
168 }170 }
169 var arr: [3:0x55]u8 = undefined;171 var arr: [3:0x55]u8 = undefined;
...@@ -225,6 +227,7 @@ test "implicit comptime in array type size" {...@@ -225,6 +227,7 @@ test "implicit comptime in array type size" {
225 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO227 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
226228
227 var arr: [plusOne(10)]bool = undefined;229 var arr: [plusOne(10)]bool = undefined;
230 _ = &arr;
228 try expect(arr.len == 11);231 try expect(arr.len == 11);
229}232}
230233
...@@ -281,6 +284,7 @@ test "anonymous list literal syntax" {...@@ -281,6 +284,7 @@ test "anonymous list literal syntax" {
281 const S = struct {284 const S = struct {
282 fn doTheTest() !void {285 fn doTheTest() !void {
283 var array: [4]u8 = .{ 1, 2, 3, 4 };286 var array: [4]u8 = .{ 1, 2, 3, 4 };
287 _ = &array;
284 try expect(array[0] == 1);288 try expect(array[0] == 1);
285 try expect(array[1] == 2);289 try expect(array[1] == 2);
286 try expect(array[2] == 3);290 try expect(array[2] == 3);
...@@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" {...@@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" {
365 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO369 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
366370
367 var two: i32 = 2;371 var two: i32 = 2;
372 _ = &two;
368 const x: []const i32 = &[_]i32{two};373 const x: []const i32 = &[_]i32{two};
369 try expect(x[0] == 2);374 try expect(x[0] == 2);
370}375}
...@@ -472,6 +477,7 @@ test "anonymous literal in array" {...@@ -472,6 +477,7 @@ test "anonymous literal in array" {
472 .{ .a = 3 },477 .{ .a = 3 },
473 .{ .b = 3 },478 .{ .b = 3 },
474 };479 };
480 _ = &array;
475 try expect(array[0].a == 3);481 try expect(array[0].a == 3);
476 try expect(array[0].b == 4);482 try expect(array[0].b == 4);
477 try expect(array[1].a == 2);483 try expect(array[1].a == 2);
...@@ -489,8 +495,10 @@ test "access the null element of a null terminated array" {...@@ -489,8 +495,10 @@ test "access the null element of a null terminated array" {
489 const S = struct {495 const S = struct {
490 fn doTheTest() !void {496 fn doTheTest() !void {
491 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };497 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
498 _ = &array;
492 try expect(array[4] == 0);499 try expect(array[4] == 0);
493 var len: usize = 4;500 var len: usize = 4;
501 _ = &len;
494 try expect(array[len] == 0);502 try expect(array[len] == 0);
495 }503 }
496 };504 };
...@@ -510,6 +518,7 @@ test "type deduction for array subscript expression" {...@@ -510,6 +518,7 @@ test "type deduction for array subscript expression" {
510 try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]);518 try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]);
511 var v1 = false;519 var v1 = false;
512 try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]);520 try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]);
521 _ = .{ &array, &v0, &v1 };
513 }522 }
514 };523 };
515 try S.doTheTest();524 try S.doTheTest();
...@@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" {...@@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" {
529 fill_post: u8 = 0xAA,538 fill_post: u8 = 0xAA,
530 };539 };
531 var x = T{};540 var x = T{};
532 var as_slice = mem.asBytes(&x);541 const as_slice = mem.asBytes(&x);
533 try expect(@as(usize, 3) == as_slice.len);542 try expect(@as(usize, 3) == as_slice.len);
534 try expect(@as(u8, 0x55) == as_slice[0]);543 try expect(@as(u8, 0x55) == as_slice[0]);
535 try expect(@as(u8, 0xAA) == as_slice[2]);544 try expect(@as(u8, 0xAA) == as_slice[2]);
...@@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" {...@@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" {
559 };568 };
560569
561 var t: S = .{ .list = .{ .s = undefined } };570 var t: S = .{ .list = .{ .s = undefined } };
571 _ = &t;
562 try expect(@as(usize, 0) == t.list.x);572 try expect(@as(usize, 0) == t.list.x);
563}573}
564574
...@@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" {...@@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" {
576586
577 fn doTheTest() !void {587 fn doTheTest() !void {
578 var x1: u8 = 42;588 var x1: u8 = 42;
589 _ = &x1;
579 const t1 = .{ x1, 56, 54 };590 const t1 = .{ x1, 56, 54 };
580 var arr1: [3]u8 = t1;591 const arr1: [3]u8 = t1;
581 try expect(arr1[0] == 42);592 try expect(arr1[0] == 42);
582 try expect(arr1[1] == 56);593 try expect(arr1[1] == 56);
583 try expect(arr1[2] == 54);594 try expect(arr1[2] == 54);
584595
585 var x2: U = .{ .a = 42 };596 var x2: U = .{ .a = 42 };
597 _ = &x2;
586 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };598 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
587 var arr2: [3]U = t2;599 const arr2: [3]U = t2;
588 try expect(arr2[0].a == 42);600 try expect(arr2[0].a == 42);
589 try expect(arr2[1].b == true);601 try expect(arr2[1].b == true);
590 try expect(mem.eql(u8, arr2[2].c, "hello"));602 try expect(mem.eql(u8, arr2[2].c, "hello"));
...@@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" {...@@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" {
608620
609 fn doTheTest() !void {621 fn doTheTest() !void {
610 var x1: u8 = 42;622 var x1: u8 = 42;
623 _ = &x1;
611 const t1 = &.{ x1, 56, 54 };624 const t1 = &.{ x1, 56, 54 };
612 var arr1: *const [3]u8 = t1;625 const arr1: *const [3]u8 = t1;
613 try expect(arr1[0] == 42);626 try expect(arr1[0] == 42);
614 try expect(arr1[1] == 56);627 try expect(arr1[1] == 56);
615 try expect(arr1[2] == 54);628 try expect(arr1[2] == 54);
616629
617 var x2: U = .{ .a = 42 };630 var x2: U = .{ .a = 42 };
631 _ = &x2;
618 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };632 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
619 var arr2: *const [3]U = t2;633 const arr2: *const [3]U = t2;
620 try expect(arr2[0].a == 42);634 try expect(arr2[0].a == 42);
621 try expect(arr2[1].b == true);635 try expect(arr2[1].b == true);
622 try expect(mem.eql(u8, arr2[2].c, "hello"));636 try expect(mem.eql(u8, arr2[2].c, "hello"));
...@@ -656,6 +670,7 @@ test "array init of container level array variable" {...@@ -656,6 +670,7 @@ test "array init of container level array variable" {
656 }670 }
657 noinline fn bar(x: usize, y: usize) void {671 noinline fn bar(x: usize, y: usize) void {
658 var tmp: [2]usize = .{ x, y };672 var tmp: [2]usize = .{ x, y };
673 _ = &tmp;
659 pair = tmp;674 pair = tmp;
660 }675 }
661 };676 };
...@@ -668,6 +683,7 @@ test "array init of container level array variable" {...@@ -668,6 +683,7 @@ test "array init of container level array variable" {
668683
669test "runtime initialized sentinel-terminated array literal" {684test "runtime initialized sentinel-terminated array literal" {
670 var c: u16 = 300;685 var c: u16 = 300;
686 _ = &c;
671 const f = &[_:0x9999]u16{c};687 const f = &[_:0x9999]u16{c};
672 const g = @as(*const [4]u8, @ptrCast(f));688 const g = @as(*const [4]u8, @ptrCast(f));
673 try std.testing.expect(g[2] == 0x99);689 try std.testing.expect(g[2] == 0x99);
...@@ -681,6 +697,7 @@ test "array of array agregate init" {...@@ -681,6 +697,7 @@ test "array of array agregate init" {
681697
682 var a = [1]u32{11} ** 10;698 var a = [1]u32{11} ** 10;
683 var b = [1][10]u32{a} ** 2;699 var b = [1][10]u32{a} ** 2;
700 _ = .{ &a, &b };
684 try std.testing.expect(b[1][1] == 11);701 try std.testing.expect(b[1][1] == 11);
685}702}
686703
...@@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" {...@@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" {
778test "slice initialized through reference to anonymous array init provides result types" {795test "slice initialized through reference to anonymous array init provides result types" {
779 var my_u32: u32 = 123;796 var my_u32: u32 = 123;
780 var my_u64: u64 = 456;797 var my_u64: u64 = 456;
798 _ = .{ &my_u32, &my_u64 };
781 const foo: []const u16 = &.{799 const foo: []const u16 = &.{
782 @intCast(my_u32),800 @intCast(my_u32),
783 @intCast(my_u64),801 @intCast(my_u64),
...@@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul...@@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul
790test "pointer to array initialized through reference to anonymous array init provides result types" {808test "pointer to array initialized through reference to anonymous array init provides result types" {
791 var my_u32: u32 = 123;809 var my_u32: u32 = 123;
792 var my_u64: u64 = 456;810 var my_u64: u64 = 456;
811 _ = .{ &my_u32, &my_u64 };
793 const foo: *const [4]u16 = &.{812 const foo: *const [4]u16 = &.{
794 @intCast(my_u32),813 @intCast(my_u32),
795 @intCast(my_u64),814 @intCast(my_u64),
test/behavior/asm.zig+1
...@@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" {...@@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" {
180 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly180 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly
181181
182 var x: u32 = 15;182 var x: u32 = 15;
183 _ = &x;
183 const double = asm ("add %[ret:w], %[in:w], %[in:w]"184 const double = asm ("add %[ret:w], %[in:w], %[in:w]"
184 : [ret] "=r" (-> u32),185 : [ret] "=r" (-> u32),
185 : [in] "r" (x),186 : [in] "r" (x),
test/behavior/async_fn.zig+22-10
...@@ -137,11 +137,13 @@ test "@frameSize" {...@@ -137,11 +137,13 @@ test "@frameSize" {
137 fn doTheTest() !void {137 fn doTheTest() !void {
138 {138 {
139 var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other));139 var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other));
140 _ = &ptr;
140 const size = @frameSize(ptr);141 const size = @frameSize(ptr);
141 try expect(size == @sizeOf(@Frame(other)));142 try expect(size == @sizeOf(@Frame(other)));
142 }143 }
143 {144 {
144 var ptr = @as(fn () callconv(.Async) void, @ptrCast(first));145 var ptr = @as(fn () callconv(.Async) void, @ptrCast(first));
146 _ = &ptr;
145 const size = @frameSize(ptr);147 const size = @frameSize(ptr);
146 try expect(size == @sizeOf(@Frame(first)));148 try expect(size == @sizeOf(@Frame(first)));
147 }149 }
...@@ -153,7 +155,7 @@ test "@frameSize" {...@@ -153,7 +155,7 @@ test "@frameSize" {
153 fn other(param: i32) void {155 fn other(param: i32) void {
154 _ = param;156 _ = param;
155 var local: i32 = undefined;157 var local: i32 = undefined;
156 _ = local;158 _ = &local;
157 suspend {}159 suspend {}
158 }160 }
159 };161 };
...@@ -239,7 +241,7 @@ test "coroutine await" {...@@ -239,7 +241,7 @@ test "coroutine await" {
239241
240 await_seq('a');242 await_seq('a');
241 var p = async await_amain();243 var p = async await_amain();
242 _ = p;244 _ = &p;
243 await_seq('f');245 await_seq('f');
244 resume await_a_promise;246 resume await_a_promise;
245 await_seq('i');247 await_seq('i');
...@@ -279,7 +281,7 @@ test "coroutine await early return" {...@@ -279,7 +281,7 @@ test "coroutine await early return" {
279281
280 early_seq('a');282 early_seq('a');
281 var p = async early_amain();283 var p = async early_amain();
282 _ = p;284 _ = &p;
283 early_seq('f');285 early_seq('f');
284 try expect(early_final_result == 1234);286 try expect(early_final_result == 1234);
285 try expect(std.mem.eql(u8, &early_points, "abcdef"));287 try expect(std.mem.eql(u8, &early_points, "abcdef"));
...@@ -329,6 +331,7 @@ test "async fn pointer in a struct field" {...@@ -329,6 +331,7 @@ test "async fn pointer in a struct field" {
329 bar: fn (*i32) callconv(.Async) void,331 bar: fn (*i32) callconv(.Async) void,
330 };332 };
331 var foo = Foo{ .bar = simpleAsyncFn2 };333 var foo = Foo{ .bar = simpleAsyncFn2 };
334 _ = &foo;
332 var bytes: [64]u8 align(16) = undefined;335 var bytes: [64]u8 align(16) = undefined;
333 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});336 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
334 try comptime expect(@TypeOf(f) == anyframe->void);337 try comptime expect(@TypeOf(f) == anyframe->void);
...@@ -367,6 +370,7 @@ test "@asyncCall with return type" {...@@ -367,6 +370,7 @@ test "@asyncCall with return type" {
367 }370 }
368 };371 };
369 var foo = Foo{ .bar = Foo.middle };372 var foo = Foo{ .bar = Foo.middle };
373 _ = &foo;
370 var bytes: [150]u8 align(16) = undefined;374 var bytes: [150]u8 align(16) = undefined;
371 var aresult: i32 = 0;375 var aresult: i32 = 0;
372 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});376 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});
...@@ -385,6 +389,7 @@ test "async fn with inferred error set" {...@@ -385,6 +389,7 @@ test "async fn with inferred error set" {
385 fn doTheTest() !void {389 fn doTheTest() !void {
386 var frame: [1]@Frame(middle) = undefined;390 var frame: [1]@Frame(middle) = undefined;
387 var fn_ptr = middle;391 var fn_ptr = middle;
392 _ = &fn_ptr;
388 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;393 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
389 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});394 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
390 resume global_frame;395 resume global_frame;
...@@ -827,7 +832,7 @@ test "alignment of local variables in async functions" {...@@ -827,7 +832,7 @@ test "alignment of local variables in async functions" {
827 const S = struct {832 const S = struct {
828 fn doTheTest() !void {833 fn doTheTest() !void {
829 var y: u8 = 123;834 var y: u8 = 123;
830 _ = y;835 _ = &y;
831 var x: u8 align(128) = 1;836 var x: u8 align(128) = 1;
832 try expect(@intFromPtr(&x) % 128 == 0);837 try expect(@intFromPtr(&x) % 128 == 0);
833 }838 }
...@@ -843,7 +848,7 @@ test "no reason to resolve frame still works" {...@@ -843,7 +848,7 @@ test "no reason to resolve frame still works" {
843}848}
844fn simpleNothing() void {849fn simpleNothing() void {
845 var x: i32 = 1234;850 var x: i32 = 1234;
846 _ = x;851 _ = &x;
847}852}
848853
849test "async call a generic function" {854test "async call a generic function" {
...@@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" {...@@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" {
913 if (x == 0) return;918 if (x == 0) return;
914 clobberStack(x - 1);919 clobberStack(x - 1);
915 var y: i32 = x;920 var y: i32 = x;
916 _ = y;921 _ = &y;
917 }922 }
918923
919 fn bar(f: *@Frame(foo)) void {924 fn bar(f: *@Frame(foo)) void {
920 var pt = Point{ .x = 1, .y = 2 };925 var pt = Point{ .x = 1, .y = 2 };
926 _ = &pt;
921 f.* = async foo(pt);927 f.* = async foo(pt);
922 var result = await f;928 const result = await f;
923 expect(result == 1) catch @panic("test failure");929 expect(result == 1) catch @panic("test failure");
924 }930 }
925931
...@@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" {...@@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" {
1141 bar: fn (*i32) callconv(.Async) i32,1147 bar: fn (*i32) callconv(.Async) i32,
1142 };1148 };
1143 var foo = Foo{ .bar = S.simple2 };1149 var foo = Foo{ .bar = S.simple2 };
1150 _ = &foo;
1144 var bytes: [64]u8 align(16) = undefined;1151 var bytes: [64]u8 align(16) = undefined;
1145 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});1152 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1146 try comptime expect(@TypeOf(f) == anyframe->i32);1153 try comptime expect(@TypeOf(f) == anyframe->i32);
...@@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {...@@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
1465 // the for loop spills still happen even though there is a VarDecl in scope1472 // the for loop spills still happen even though there is a VarDecl in scope
1466 // before the suspend.1473 // before the suspend.
1467 var anything = true;1474 var anything = true;
1468 _ = anything;1475 _ = &anything;
1469 suspend {1476 suspend {
1470 global_frame = @frame();1477 global_frame = @frame();
1471 }1478 }
...@@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" {...@@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" {
15381545
1539 fn foo() void {1546 fn foo() void {
1540 var a: u128 = 99;1547 var a: u128 = 99;
1548 _ = &a;
1541 bar(10, .{a}) catch unreachable;1549 bar(10, .{a}) catch unreachable;
1542 }1550 }
15431551
...@@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" {...@@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" {
1590 const stack_size = 1000;1598 const stack_size = 1000;
1591 var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined;1599 var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined;
1592 var func: fn () callconv(.Async) anyerror!void = bar;1600 var func: fn () callconv(.Async) anyerror!void = bar;
1601 _ = &func;
1593 return await @asyncCall(&stack_frame, {}, func, .{});1602 return await @asyncCall(&stack_frame, {}, func, .{});
1594 }1603 }
15951604
...@@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" {...@@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" {
16141623
1615 fn foo() void {1624 fn foo() void {
1616 var opt: ?usize = 1234;1625 var opt: ?usize = 1234;
1626 _ = &opt;
1617 if (opt) |x| {1627 if (opt) |x| {
1618 bar();1628 bar();
1619 global_int += x;1629 global_int += x;
...@@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" {...@@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" {
1863 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;1873 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
1864 // The function pointer must not be comptime-known.1874 // The function pointer must not be comptime-known.
1865 var t = S.f;1875 var t = S.f;
1876 _ = &t;
1866 var frame_ptr = @asyncCall(&buffer, {}, t, .{1877 var frame_ptr = @asyncCall(&buffer, {}, t, .{
1867 F0,1878 F0,
1868 .{ .f0 = 1, .f1 = 2 },1879 .{ .f0 = 1, .f1 = 2 },
...@@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" {...@@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" {
1870 [_]u8{ 1, 2, 3, 4, 5 },1881 [_]u8{ 1, 2, 3, 4, 5 },
1871 F2,1882 F2,
1872 });1883 });
1873 _ = frame_ptr;1884 _ = &frame_ptr;
1874}1885}
18751886
1876test "@asyncCall with arguments having non-standard alignment" {1887test "@asyncCall with arguments having non-standard alignment" {
...@@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" {...@@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" {
1893 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;1904 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
1894 // The function pointer must not be comptime-known.1905 // The function pointer must not be comptime-known.
1895 var t = S.f;1906 var t = S.f;
1907 _ = &t;
1896 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });1908 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });
1897 _ = frame_ptr;1909 _ = &frame_ptr;
1898}1910}
test/behavior/await_struct.zig+1-1
...@@ -14,7 +14,7 @@ test "coroutine await struct" {...@@ -14,7 +14,7 @@ test "coroutine await struct" {
1414
15 await_seq('a');15 await_seq('a');
16 var p = async await_amain();16 var p = async await_amain();
17 _ = p;17 _ = &p;
18 await_seq('f');18 await_seq('f');
19 resume await_a_promise;19 resume await_a_promise;
20 await_seq('i');20 await_seq('i');
test/behavior/basic.zig+16-3
...@@ -118,6 +118,7 @@ fn thisIsAColdFn() void {...@@ -118,6 +118,7 @@ fn thisIsAColdFn() void {
118118
119test "unicode escape in character literal" {119test "unicode escape in character literal" {
120 var a: u24 = '\u{01f4a9}';120 var a: u24 = '\u{01f4a9}';
121 _ = &a;
121 try expect(a == 128169);122 try expect(a == 128169);
122}123}
123124
...@@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" {...@@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" {
362}363}
363fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {364fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
364 var a = ptr;365 var a = ptr;
366 _ = &a;
365 return a;367 return a;
366}368}
367369
...@@ -441,6 +443,7 @@ test "double implicit cast in same expression" {...@@ -441,6 +443,7 @@ test "double implicit cast in same expression" {
441 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO443 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
442444
443 var x = @as(i32, @as(u16, nine()));445 var x = @as(i32, @as(u16, nine()));
446 _ = &x;
444 try expect(x == 9);447 try expect(x == 9);
445}448}
446fn nine() u8 {449fn nine() u8 {
...@@ -570,6 +573,7 @@ test "comptime cast fn to ptr" {...@@ -570,6 +573,7 @@ test "comptime cast fn to ptr" {
570573
571test "equality compare fn ptrs" {574test "equality compare fn ptrs" {
572 var a = &emptyFn;575 var a = &emptyFn;
576 _ = &a;
573 try expect(a == a);577 try expect(a == a);
574}578}
575579
...@@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" {...@@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" {
611 const S = struct {615 const S = struct {
612 fn doTheTest() !void {616 fn doTheTest() !void {
613 var index: usize = 1;617 var index: usize = 1;
618 _ = &index;
614 const ptr = &pieces[index].field;619 const ptr = &pieces[index].field;
615 try expect(ptr.* == 2);620 try expect(ptr.* == 2);
616 }621 }
...@@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" {...@@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" {
785790
786test "if expression type coercion" {791test "if expression type coercion" {
787 var cond: bool = true;792 var cond: bool = true;
793 _ = &cond;
788 const x: u16 = if (cond) 1 else 0;794 const x: u16 = if (cond) 1 else 0;
789 try expect(@as(u16, x) == 1);795 try expect(@as(u16, x) == 1);
790}796}
...@@ -825,6 +831,7 @@ test "discarding the result of various expressions" {...@@ -825,6 +831,7 @@ test "discarding the result of various expressions" {
825831
826test "labeled block implicitly ends in a break" {832test "labeled block implicitly ends in a break" {
827 var a = false;833 var a = false;
834 _ = &a;
828 blk: {835 blk: {
829 if (a) break :blk;836 if (a) break :blk;
830 }837 }
...@@ -852,6 +859,7 @@ test "catch in block has correct result location" {...@@ -852,6 +859,7 @@ test "catch in block has correct result location" {
852test "labeled block with runtime branch forwards its result location type to break statements" {859test "labeled block with runtime branch forwards its result location type to break statements" {
853 const E = enum { a, b };860 const E = enum { a, b };
854 var a = false;861 var a = false;
862 _ = &a;
855 const e: E = blk: {863 const e: E = blk: {
856 if (a) {864 if (a) {
857 break :blk .a;865 break :blk .a;
...@@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" {...@@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" {
872 };880 };
873 const s: ?*S = blk: {881 const s: ?*S = blk: {
874 var a = try S.foo();882 var a = try S.foo();
875883 _ = &a;
876 _ = a;
877 break :blk null;884 break :blk null;
878 };885 };
879 _ = s;886 _ = s;
...@@ -894,6 +901,7 @@ test "weird array and tuple initializations" {...@@ -894,6 +901,7 @@ test "weird array and tuple initializations" {
894 const E = enum { a, b };901 const E = enum { a, b };
895 const S = struct { e: E };902 const S = struct { e: E };
896 var a = false;903 var a = false;
904 _ = &a;
897 const b = S{ .e = .a };905 const b = S{ .e = .a };
898906
899 _ = &[_]S{907 _ = &[_]S{
...@@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" {...@@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" {
1009 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1017 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10101018
1011 var a: u32 = 0;1019 var a: u32 = 0;
1020 _ = &a;
1012 var b: [2]u32 = undefined;1021 var b: [2]u32 = undefined;
1013 b[0] = @as(u32, switch (a) {1022 b[0] = @as(u32, switch (a) {
1014 1 => 1,1023 1 => 1,
...@@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" {...@@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" {
1110 }1119 }
1111 };1120 };
1112 var optional: ?Loc = .{};1121 var optional: ?Loc = .{};
1113 var foo = Container.init(optional orelse .{});1122 _ = &optional;
1123 const foo = Container.init(optional orelse .{});
1114 try expect(foo.a.?.start == -1);1124 try expect(foo.a.?.start == -1);
1115}1125}
11161126
...@@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" {...@@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" {
1153test "pointer to struct literal with runtime field is constant" {1163test "pointer to struct literal with runtime field is constant" {
1154 const S = struct { data: usize };1164 const S = struct { data: usize };
1155 var runtime_zero: usize = 0;1165 var runtime_zero: usize = 0;
1166 _ = &runtime_zero;
1156 const ptr = &S{ .data = runtime_zero };1167 const ptr = &S{ .data = runtime_zero };
1157 try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const);1168 try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const);
1158}1169}
...@@ -1163,6 +1174,7 @@ test "integer compare" {...@@ -1163,6 +1174,7 @@ test "integer compare" {
1163 var z: T = 0;1174 var z: T = 0;
1164 var p: T = 123;1175 var p: T = 123;
1165 var n: T = -123;1176 var n: T = -123;
1177 _ = .{ &z, &p, &n };
1166 try expect(z == z and z != p and z != n);1178 try expect(z == z and z != p and z != n);
1167 try expect(p == p and p != n and n == n);1179 try expect(p == p and p != n and n == n);
1168 try expect(z > n and z < p and z >= n and z <= p);1180 try expect(z > n and z < p and z >= n and z <= p);
...@@ -1180,6 +1192,7 @@ test "integer compare" {...@@ -1180,6 +1192,7 @@ test "integer compare" {
1180 fn doTheTestUnsigned(comptime T: type) !void {1192 fn doTheTestUnsigned(comptime T: type) !void {
1181 var z: T = 0;1193 var z: T = 0;
1182 var p: T = 123;1194 var p: T = 123;
1195 _ = .{ &z, &p };
1183 try expect(z == z and z != p);1196 try expect(z == z and z != p);
1184 try expect(p == p);1197 try expect(p == p);
1185 try expect(z < p and z <= p);1198 try expect(z < p and z <= p);
test/behavior/bit_shifting.zig+2-2
...@@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c...@@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
99// #222599// #2225
100test "comptime shr of BigInt" {100test "comptime shr of BigInt" {
101 comptime {101 comptime {
102 var n0 = 0xdeadbeef0000000000000000;102 const n0 = 0xdeadbeef0000000000000000;
103 try expect(n0 >> 64 == 0xdeadbeef);103 try expect(n0 >> 64 == 0xdeadbeef);
104 var n1 = 17908056155735594659;104 const n1 = 17908056155735594659;
105 try expect(n1 >> 64 == 0);105 try expect(n1 >> 64 == 0);
106 }106 }
107}107}
test/behavior/bitcast.zig+19-7
...@@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" {...@@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" {
149}149}
150150
151test "bitcast generates a temporary value" {151test "bitcast generates a temporary value" {
152 var y = @as(u16, 0x55AA);152 var y: u16 = 0x55AA;
153 const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y))));153 _ = &y;
154 const x: u16 = @bitCast(@as([2]u8, @bitCast(y)));
154 try expect(y == x);155 try expect(y == x);
155}156}
156157
...@@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" {...@@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" {
171 const S = struct {172 const S = struct {
172 fn doTheTest() !void {173 fn doTheTest() !void {
173 var full = Full{ .number = 0x1234 };174 var full = Full{ .number = 0x1234 };
174 var two_halves = @as(Divided, @bitCast(full));175 _ = &full;
176 const two_halves: Divided = @bitCast(full);
175 try expect(two_halves.half1 == 0x34);177 try expect(two_halves.half1 == 0x34);
176 try expect(two_halves.quarter3 == 0x2);178 try expect(two_halves.quarter3 == 0x2);
177 try expect(two_halves.quarter4 == 0x1);179 try expect(two_halves.quarter4 == 0x1);
...@@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" {...@@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" {
195 const S = struct {197 const S = struct {
196 fn doTheTest() !void {198 fn doTheTest() !void {
197 var full = Full{ .number = 0x1234 };199 var full = Full{ .number = 0x1234 };
198 var two_halves = @as(TwoHalves, @bitCast(full));200 _ = &full;
201 const two_halves: TwoHalves = @bitCast(full);
199 switch (native_endian) {202 switch (native_endian) {
200 .big => {203 .big => {
201 try expect(two_halves.half1 == 0x12);204 try expect(two_halves.half1 == 0x12);
...@@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" {...@@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" {
225 const S = struct {228 const S = struct {
226 fn doTheTest() !void {229 fn doTheTest() !void {
227 var move = LevelUpMove{ .move_id = 1, .level = 2 };230 var move = LevelUpMove{ .move_id = 1, .level = 2 };
228 var v = @as(u16, @bitCast(move));231 _ = &move;
229 var back_to_a_move = @as(LevelUpMove, @bitCast(v));232 const v: u16 = @bitCast(move);
233 const back_to_a_move: LevelUpMove = @bitCast(v);
230 try expect(back_to_a_move.move_id == 1);234 try expect(back_to_a_move.move_id == 1);
231 try expect(back_to_a_move.level == 2);235 try expect(back_to_a_move.level == 2);
232 }236 }
...@@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" {...@@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" {
312 const S = struct {316 const S = struct {
313 fn doTheTest() !void {317 fn doTheTest() !void {
314 var foo = Foo{};318 var foo = Foo{};
315 var v = @as(Foo2, @bitCast(foo));319 _ = &foo;
320 const v: Foo2 = @bitCast(foo);
316 try expect(v.a == foo.a);321 try expect(v.a == foo.a);
317 try expect(v.b == foo.b);322 try expect(v.b == foo.b);
318 try expect(v.c == foo.c);323 try expect(v.c == foo.c);
...@@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" {...@@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" {
354359
355 // S -> Int360 // S -> Int
356 var s: S = .{};361 var s: S = .{};
362 _ = &s;
357 try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{})));363 try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{})));
358364
359 // Int -> S365 // Int -> S
360 var i: Int = 0;366 var i: Int = 0;
367 _ = &i;
361 const rt_cast = @as(S, @bitCast(i));368 const rt_cast = @as(S, @bitCast(i));
362 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));369 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
363 inline for (@typeInfo(S).Struct.fields) |field| {370 inline for (@typeInfo(S).Struct.fields) |field| {
...@@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" {...@@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" {
376 const FloatT = extern struct { f: f80, x: u128 align(16) };383 const FloatT = extern struct { f: f80, x: u128 align(16) };
377 const x: FloatT = .{ .f = 0.5, .x = 123 };384 const x: FloatT = .{ .f = 0.5, .x = 123 };
378 var x_as_uint: u256 = comptime @as(u256, @bitCast(x));385 var x_as_uint: u256 = comptime @as(u256, @bitCast(x));
386 _ = &x_as_uint;
379387
380 try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);388 try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);
381 try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);389 try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);
...@@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" {...@@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" {
428 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const));436 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const));
429437
430 var snan_f16_var = math.snan(f16);438 var snan_f16_var = math.snan(f16);
439 _ = &snan_f16_var;
431 try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var)));440 try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var)));
432 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var));441 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var));
433442
...@@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" {...@@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" {
437 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const));446 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const));
438447
439 var snan_f32_var = math.snan(f32);448 var snan_f32_var = math.snan(f32);
449 _ = &snan_f32_var;
440 try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var)));450 try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var)));
441 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var));451 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var));
442452
...@@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" {...@@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" {
446 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const));456 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const));
447457
448 var snan_f64_var = math.snan(f64);458 var snan_f64_var = math.snan(f64);
459 _ = &snan_f64_var;
449 try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var)));460 try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var)));
450 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var));461 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var));
451462
...@@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" {...@@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" {
455 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const));466 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const));
456467
457 var snan_f128_var = math.snan(f128);468 var snan_f128_var = math.snan(f128);
469 _ = &snan_f128_var;
458 try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var)));470 try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var)));
459 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var));471 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var));
460}472}
test/behavior/bitreverse.zig+26-4
...@@ -86,11 +86,30 @@ fn testBitReverse() !void {...@@ -86,11 +86,30 @@ fn testBitReverse() !void {
86 try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24));86 try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24));
87 var neg32: i32 = -16773785;87 var neg32: i32 = -16773785;
88 try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32));88 try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32));
89
90 _ = .{
91 &num0,
92 &num5,
93 &num8,
94 &num16,
95 &num24,
96 &num32,
97 &num40,
98 &num48,
99 &num56,
100 &num64,
101 &num128,
102 &neg8,
103 &neg16,
104 &neg24,
105 &neg32,
106 };
89}107}
90108
91fn vector8() !void {109fn vector8() !void {
92 var v = @Vector(2, u8){ 0x12, 0x23 };110 var v = @Vector(2, u8){ 0x12, 0x23 };
93 var result = @bitReverse(v);111 _ = &v;
112 const result = @bitReverse(v);
94 try expect(result[0] == 0x48);113 try expect(result[0] == 0x48);
95 try expect(result[1] == 0xc4);114 try expect(result[1] == 0xc4);
96}115}
...@@ -109,7 +128,8 @@ test "bitReverse vectors u8" {...@@ -109,7 +128,8 @@ test "bitReverse vectors u8" {
109128
110fn vector16() !void {129fn vector16() !void {
111 var v = @Vector(2, u16){ 0x1234, 0x2345 };130 var v = @Vector(2, u16){ 0x1234, 0x2345 };
112 var result = @bitReverse(v);131 _ = &v;
132 const result = @bitReverse(v);
113 try expect(result[0] == 0x2c48);133 try expect(result[0] == 0x2c48);
114 try expect(result[1] == 0xa2c4);134 try expect(result[1] == 0xa2c4);
115}135}
...@@ -128,7 +148,8 @@ test "bitReverse vectors u16" {...@@ -128,7 +148,8 @@ test "bitReverse vectors u16" {
128148
129fn vector24() !void {149fn vector24() !void {
130 var v = @Vector(2, u24){ 0x123456, 0x234567 };150 var v = @Vector(2, u24){ 0x123456, 0x234567 };
131 var result = @bitReverse(v);151 _ = &v;
152 const result = @bitReverse(v);
132 try expect(result[0] == 0x6a2c48);153 try expect(result[0] == 0x6a2c48);
133 try expect(result[1] == 0xe6a2c4);154 try expect(result[1] == 0xe6a2c4);
134}155}
...@@ -147,7 +168,8 @@ test "bitReverse vectors u24" {...@@ -147,7 +168,8 @@ test "bitReverse vectors u24" {
147168
148fn vector0() !void {169fn vector0() !void {
149 var v = @Vector(2, u0){ 0, 0 };170 var v = @Vector(2, u0){ 0, 0 };
150 var result = @bitReverse(v);171 _ = &v;
172 const result = @bitReverse(v);
151 try expect(result[0] == 0);173 try expect(result[0] == 0);
152 try expect(result[1] == 0);174 try expect(result[1] == 0);
153}175}
test/behavior/bugs/10147.zig+4-2
...@@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" {...@@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" {
10 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;10 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1111
12 var x: u32 = 0x1;12 var x: u32 = 0x1;
13 _ = &x;
13 var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };14 var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
14 var a = @clz(x);15 _ = &y;
15 var b = @clz(y);16 const a = @clz(x);
17 const b = @clz(y);
16 try std.testing.expectEqual(@as(u6, 31), a);18 try std.testing.expectEqual(@as(u6, 31), a);
17 try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);19 try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
18}20}
test/behavior/bugs/10970.zig+1
...@@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" {...@@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" {
9 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO9 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1010
11 var cond = true;11 var cond = true;
12 _ = &cond;
12 const opt = while (cond) {13 const opt = while (cond) {
13 if (retOpt()) |opt| {14 if (retOpt()) |opt| {
14 break opt;15 break opt;
test/behavior/bugs/11046.zig+1
...@@ -2,6 +2,7 @@ const builtin = @import("builtin");...@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22
3fn foo() !void {3fn foo() !void {
4 var a = true;4 var a = true;
5 _ = &a;
5 if (a) return error.Foo;6 if (a) return error.Foo;
6 return error.Bar;7 return error.Bar;
7}8}
test/behavior/bugs/11139.zig+1
...@@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 {...@@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 {
21 S{ .x = 15 },21 S{ .x = 15 },
22 },22 },
23 };23 };
24 _ = &cases;
24 return cases[0][0].x;25 return cases[0][0].x;
25}26}
test/behavior/bugs/11159.zig+3-3
...@@ -4,7 +4,7 @@ const builtin = @import("builtin");...@@ -4,7 +4,7 @@ const builtin = @import("builtin");
4test {4test {
5 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });5 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
6 var a: T = .{ 0, 0 };6 var a: T = .{ 0, 0 };
7 _ = a;7 _ = &a;
8}8}
99
10test {10test {
...@@ -13,7 +13,7 @@ test {...@@ -13,7 +13,7 @@ test {
13 comptime y: u32 = 0,13 comptime y: u32 = 0,
14 };14 };
15 var a: S = .{};15 var a: S = .{};
16 _ = a;16 _ = &a;
17 var b = S{};17 var b = S{};
18 _ = b;18 _ = &b;
19}19}
test/behavior/bugs/11162.zig+2-1
...@@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin...@@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin
6 if (true) return error.SkipZigTest; // TODO6 if (true) return error.SkipZigTest; // TODO
77
8 var x: u32 = 15;8 var x: u32 = 15;
9 _ = &x;
9 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });10 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
10 var a: T = .{ -1234, 5678, x + 1 };11 const a: T = .{ -1234, 5678, x + 1 };
1112
12 try expect(a[0] == -1234);13 try expect(a[0] == -1234);
13 try expect(a[1] == 5678);14 try expect(a[1] == 5678);
test/behavior/bugs/11165.zig+2-2
...@@ -18,7 +18,7 @@ test "bytes" {...@@ -18,7 +18,7 @@ test "bytes" {
18 };18 };
1919
20 var u_2 = U{ .s = s_1 };20 var u_2 = U{ .s = s_1 };
21 _ = u_2;21 _ = &u_2;
22}22}
2323
24test "aggregate" {24test "aggregate" {
...@@ -40,5 +40,5 @@ test "aggregate" {...@@ -40,5 +40,5 @@ test "aggregate" {
40 };40 };
4141
42 var u_2 = U{ .s = s_1 };42 var u_2 = U{ .s = s_1 };
43 _ = u_2;43 _ = &u_2;
44}44}
test/behavior/bugs/11181.zig+1-1
...@@ -21,5 +21,5 @@ test "var inferred array of slices" {...@@ -21,5 +21,5 @@ test "var inferred array of slices" {
21 .{ .v = false },21 .{ .v = false },
22 },22 },
23 };23 };
24 _ = decls;24 _ = &decls;
25}25}
test/behavior/bugs/12000.zig+1
...@@ -11,5 +11,6 @@ test {...@@ -11,5 +11,6 @@ test {
11 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO11 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1212
13 var t: T = .{ .next = null };13 var t: T = .{ .next = null };
14 _ = &t;
14 try std.testing.expect(t.next == null);15 try std.testing.expect(t.next == null);
15}16}
test/behavior/bugs/12025.zig+1
...@@ -5,6 +5,7 @@ test {...@@ -5,6 +5,7 @@ test {
5 .foo = &1,5 .foo = &1,
6 .bar = &2,6 .bar = &2,
7 };7 };
8 _ = &st;
89
9 inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {10 inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
10 _ = field;11 _ = field;
test/behavior/bugs/12092.zig+1
...@@ -19,6 +19,7 @@ test {...@@ -19,6 +19,7 @@ test {
19 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO19 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2020
21 var baz: u32 = 24;21 var baz: u32 = 24;
22 _ = &baz;
22 try takeFoo(&.{23 try takeFoo(&.{
23 .a = .{24 .a = .{
24 .b = baz,25 .b = baz,
test/behavior/bugs/12498.zig+1
...@@ -4,5 +4,6 @@ const expect = std.testing.expect;...@@ -4,5 +4,6 @@ const expect = std.testing.expect;
4const S = struct { a: usize };4const S = struct { a: usize };
5test "lazy abi size used in comparison" {5test "lazy abi size used in comparison" {
6 var rhs: i32 = 100;6 var rhs: i32 = 100;
7 _ = &rhs;
7 try expect(@sizeOf(S) < rhs);8 try expect(@sizeOf(S) < rhs);
8}9}
test/behavior/bugs/12776.zig+1
...@@ -22,6 +22,7 @@ const CPU = packed struct {...@@ -22,6 +22,7 @@ const CPU = packed struct {
22 }22 }
23 fn tick(self: *CPU) !void {23 fn tick(self: *CPU) !void {
24 var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);24 var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);
25 _ = &queued_interrupts;
25 if (self.interrupts and queued_interrupts != 0) {26 if (self.interrupts and queued_interrupts != 0) {
26 self.interrupts = false;27 self.interrupts = false;
27 }28 }
test/behavior/bugs/12891.zig+5
...@@ -4,26 +4,31 @@ const builtin = @import("builtin");...@@ -4,26 +4,31 @@ const builtin = @import("builtin");
4test "issue12891" {4test "issue12891" {
5 const f = 10.0;5 const f = 10.0;
6 var i: usize = 0;6 var i: usize = 0;
7 _ = &i;
7 try std.testing.expect(i < f);8 try std.testing.expect(i < f);
8}9}
9test "nan" {10test "nan" {
10 const f = comptime std.math.nan(f64);11 const f = comptime std.math.nan(f64);
11 var i: usize = 0;12 var i: usize = 0;
13 _ = &i;
12 try std.testing.expect(!(f < i));14 try std.testing.expect(!(f < i));
13}15}
14test "inf" {16test "inf" {
15 const f = comptime std.math.inf(f64);17 const f = comptime std.math.inf(f64);
16 var i: usize = 0;18 var i: usize = 0;
19 _ = &i;
17 try std.testing.expect(f > i);20 try std.testing.expect(f > i);
18}21}
19test "-inf < 0" {22test "-inf < 0" {
20 const f = comptime -std.math.inf(f64);23 const f = comptime -std.math.inf(f64);
21 var i: usize = 0;24 var i: usize = 0;
25 _ = &i;
22 try std.testing.expect(f < i);26 try std.testing.expect(f < i);
23}27}
24test "inf >= 1" {28test "inf >= 1" {
25 const f = comptime std.math.inf(f64);29 const f = comptime std.math.inf(f64);
26 var i: usize = 1;30 var i: usize = 1;
31 _ = &i;
27 try std.testing.expect(f >= i);32 try std.testing.expect(f >= i);
28}33}
29test "isNan(nan * 1)" {34test "isNan(nan * 1)" {
test/behavior/bugs/12972.zig+1
...@@ -12,6 +12,7 @@ test {...@@ -12,6 +12,7 @@ test {
12 f(&.{c});12 f(&.{c});
1313
14 var v: u8 = 42;14 var v: u8 = 42;
15 _ = &v;
15 f(&[_:null]?u8{v});16 f(&[_:null]?u8{v});
16 f(&.{v});17 f(&.{v});
17}18}
test/behavior/bugs/12984.zig+1-1
...@@ -16,5 +16,5 @@ test "simple test" {...@@ -16,5 +16,5 @@ test "simple test" {
16 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO16 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1717
18 var c: CustomDraw = undefined;18 var c: CustomDraw = undefined;
19 _ = c;19 _ = &c;
20}20}
test/behavior/bugs/13128.zig+1
...@@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" {...@@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" {
18 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;18 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1919
20 var x: u8 = 1;20 var x: u8 = 1;
21 _ = &x;
21 try foo(.{ .x = x });22 try foo(.{ .x = x });
2223
23 const val: U = @unionInit(U, "x", x);24 const val: U = @unionInit(U, "x", x);
test/behavior/bugs/13159.zig+1
...@@ -13,5 +13,6 @@ test {...@@ -13,5 +13,6 @@ test {
13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1414
15 var foo = Bar.Baz.fizz;15 var foo = Bar.Baz.fizz;
16 _ = &foo;
16 try expect(foo == .fizz);17 try expect(foo == .fizz);
17}18}
test/behavior/bugs/13285.zig+1-1
...@@ -8,7 +8,7 @@ test {...@@ -8,7 +8,7 @@ test {
8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
99
10 var a: Crasher = undefined;10 var a: Crasher = undefined;
11 var crasher_ptr = &a;11 const crasher_ptr = &a;
12 var crasher_local = crasher_ptr.*;12 var crasher_local = crasher_ptr.*;
13 const crasher_local_ptr = &crasher_local;13 const crasher_local_ptr = &crasher_local;
14 crasher_local_ptr.lets_crash = 1;14 crasher_local_ptr.lets_crash = 1;
test/behavior/bugs/13366.zig+2
...@@ -18,9 +18,11 @@ test {...@@ -18,9 +18,11 @@ test {
18 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO18 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1919
20 var a: u32 = 16;20 var a: u32 = 16;
21 _ = &a;
21 var reason = .{ .c_import = .{ .a = a } };22 var reason = .{ .c_import = .{ .a = a } };
22 var block = Block{23 var block = Block{
23 .reason = &reason,24 .reason = &reason,
24 };25 };
26 _ = &block;
25 try expect(block.reason.?.c_import.a == 16);27 try expect(block.reason.?.c_import.a == 16);
26}28}
test/behavior/bugs/13714.zig+1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1comptime {1comptime {
2 var image: [1]u8 = undefined;2 var image: [1]u8 = undefined;
3 _ = &image;
3 _ = @shlExact(@as(u16, image[0]), 8);4 _ = @shlExact(@as(u16, image[0]), 8);
4}5}
test/behavior/bugs/13785.zig+1
...@@ -9,5 +9,6 @@ test {...@@ -9,5 +9,6 @@ test {
9 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;9 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1010
11 var a: u8 = 0;11 var a: u8 = 0;
12 _ = &a;
12 try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });13 try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
13}14}
test/behavior/bugs/1381.zig+1
...@@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" {...@@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" {
20 A{ .B = B{ .D = 1 } },20 A{ .B = B{ .D = 1 } },
21 A{ .B = B{ .D = 1 } },21 A{ .B = B{ .D = 1 } },
22 };22 };
23 _ = &as;
2324
24 const a = as[0].B;25 const a = as[0].B;
25 try std.testing.expect(a.D == 1);26 try std.testing.expect(a.D == 1);
test/behavior/bugs/1442.zig+1
...@@ -12,5 +12,6 @@ test "const error union field alignment" {...@@ -12,5 +12,6 @@ test "const error union field alignment" {
12 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO12 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1313
14 var union_or_err: anyerror!Union = Union{ .Color = 1234 };14 var union_or_err: anyerror!Union = Union{ .Color = 1234 };
15 _ = &union_or_err;
15 try std.testing.expect((union_or_err catch unreachable).Color == 1234);16 try std.testing.expect((union_or_err catch unreachable).Color == 1234);
16}17}
test/behavior/bugs/1500.zig+1
...@@ -8,6 +8,7 @@ const B = *const fn (A) void;...@@ -8,6 +8,7 @@ const B = *const fn (A) void;
8test "allow these dependencies" {8test "allow these dependencies" {
9 var a: A = undefined;9 var a: A = undefined;
10 var b: B = undefined;10 var b: B = undefined;
11 _ = .{ &a, &b };
11 if (false) {12 if (false) {
12 a;13 a;
13 b;14 b;
test/behavior/bugs/1735.zig+1-1
...@@ -45,6 +45,6 @@ test "initialization" {...@@ -45,6 +45,6 @@ test "initialization" {
45 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;45 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
46 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO46 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
4747
48 var t = a.init();48 const t = a.init();
49 try std.testing.expect(t.foo.len == 0);49 try std.testing.expect(t.foo.len == 0);
50}50}
test/behavior/bugs/2557.zig+1-1
...@@ -2,5 +2,5 @@ test {...@@ -2,5 +2,5 @@ test {
2 var a = if (true) {2 var a = if (true) {
3 return;3 return;
4 } else true;4 } else true;
5 _ = a;5 _ = &a;
6}6}
test/behavior/bugs/3468.zig+1
...@@ -3,4 +3,5 @@ test "pointer deref next to assignment" {...@@ -3,4 +3,5 @@ test "pointer deref next to assignment" {
3 var a:i32=2;3 var a:i32=2;
4 var b=&a;4 var b=&a;
5 b.*=3;5 b.*=3;
6 _=&b;
6}7}
test/behavior/bugs/3586.zig+1-1
...@@ -12,5 +12,5 @@ test "fixed" {...@@ -12,5 +12,5 @@ test "fixed" {
12 var ctr = Container{12 var ctr = Container{
13 .params = NoteParams{},13 .params = NoteParams{},
14 };14 };
15 _ = ctr;15 _ = &ctr;
16}16}
test/behavior/bugs/4560.zig+1
...@@ -11,6 +11,7 @@ test "fixed" {...@@ -11,6 +11,7 @@ test "fixed" {
11 .max_distance_from_start_index = 456,11 .max_distance_from_start_index = 456,
12 },12 },
13 };13 };
14 _ = &s;
14 try std.testing.expect(s.a == 1);15 try std.testing.expect(s.a == 1);
15 try std.testing.expect(s.b.size == 123);16 try std.testing.expect(s.b.size == 123);
16 try std.testing.expect(s.b.max_distance_from_start_index == 456);17 try std.testing.expect(s.b.max_distance_from_start_index == 456);
test/behavior/bugs/6047.zig+1
...@@ -6,6 +6,7 @@ fn getError() !void {...@@ -6,6 +6,7 @@ fn getError() !void {
66
7fn getError2() !void {7fn getError2() !void {
8 var a: u8 = 'c';8 var a: u8 = 'c';
9 _ = &a;
9 try if (a == 'a') getError() else if (a == 'b') getError() else getError();10 try if (a == 'a') getError() else if (a == 'b') getError() else getError();
10}11}
1112
test/behavior/bugs/624.zig+1
...@@ -25,5 +25,6 @@ test "foo" {...@@ -25,5 +25,6 @@ test "foo" {
25 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO25 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2626
27 var allocator = ContextAllocator{ .n = 10 };27 var allocator = ContextAllocator{ .n = 10 };
28 _ = &allocator;
28 try expect(allocator.n == 10);29 try expect(allocator.n == 10);
29}30}
test/behavior/bugs/656.zig+1
...@@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void {...@@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void {
22 var prefix_op = PrefixOp{22 var prefix_op = PrefixOp{
23 .AddrOf = Value{ .align_expr = 1234 },23 .AddrOf = Value{ .align_expr = 1234 },
24 };24 };
25 _ = &prefix_op;
25 if (a) {} else {26 if (a) {} else {
26 switch (prefix_op) {27 switch (prefix_op) {
27 PrefixOp.AddrOf => |addr_of_info| {28 PrefixOp.AddrOf => |addr_of_info| {
test/behavior/bugs/6781.zig+2-1
...@@ -51,7 +51,8 @@ pub const JournalHeader = packed struct {...@@ -51,7 +51,8 @@ pub const JournalHeader = packed struct {
51 return @as(u128, @bitCast(target[0..hash_chain_root_size].*));51 return @as(u128, @bitCast(target[0..hash_chain_root_size].*));
52 } else {52 } else {
53 var array = target[0..hash_chain_root_size].*;53 var array = target[0..hash_chain_root_size].*;
54 return @as(u128, @bitCast(array));54 _ = &array;
55 return @bitCast(array);
55 }56 }
56 }57 }
5758
test/behavior/bugs/679.zig+1
...@@ -14,5 +14,6 @@ const Element = struct {...@@ -14,5 +14,6 @@ const Element = struct {
14test "false dependency loop in struct definition" {14test "false dependency loop in struct definition" {
15 const listType = ElementList;15 const listType = ElementList;
16 var x: listType = 42;16 var x: listType = 42;
17 _ = &x;
17 try expect(x == 42);18 try expect(x == 42);
18}19}
test/behavior/bugs/6905.zig+5-3
...@@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" {...@@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
88
9 var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };9 const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
1010
11 var index: u8 = 2;11 var index: u8 = 2;
12 var slice = u32s[index..index :2];12 _ = &index;
13 var array_ptr = u32s[2..2 :2];13 const slice = u32s[index..index :2];
14 const array_ptr = u32s[2..2 :2];
14 const comptime_known_array_value = u32s[2..2 :2].*;15 const comptime_known_array_value = u32s[2..2 :2].*;
15 var runtime_array_value = u32s[2..2 :2].*;16 var runtime_array_value = u32s[2..2 :2].*;
17 _ = &runtime_array_value;
1618
17 try expect(slice[0] == 2);19 try expect(slice[0] == 2);
18 try expect(array_ptr[0] == 2);20 try expect(array_ptr[0] == 2);
test/behavior/bugs/7187.zig+1-1
...@@ -5,7 +5,7 @@ const expect = std.testing.expect;...@@ -5,7 +5,7 @@ const expect = std.testing.expect;
5test "miscompilation with bool return type" {5test "miscompilation with bool return type" {
6 var x: usize = 1;6 var x: usize = 1;
7 var y: bool = getFalse();7 var y: bool = getFalse();
8 _ = y;8 _ = .{ &x, &y };
99
10 try expect(x == 1);10 try expect(x == 1);
11}11}
test/behavior/bugs/726.zig+4-2
...@@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" {...@@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" {
7 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO7 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
88
9 const c: u8 = 4;9 const c: u8 = 4;
10 var x: ?*const u8 = @as(?*const u8, @ptrCast(&c));10 var x: ?*const u8 = @ptrCast(&c);
11 _ = &x;
11 try expect(x.?.* == 4);12 try expect(x.?.* == 4);
12}13}
1314
...@@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" {...@@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" {
19 const container = struct {20 const container = struct {
20 var c: u8 = 4;21 var c: u8 = 4;
21 };22 };
22 var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c));23 var x: ?*const u8 = @ptrCast(&container.c);
24 _ = &x;
23 try expect(x.?.* == 4);25 try expect(x.?.* == 4);
24}26}
test/behavior/bugs/7325.zig+2
...@@ -85,6 +85,7 @@ test {...@@ -85,6 +85,7 @@ test {
85 var param: ParamType = .{85 var param: ParamType = .{
86 .one_of = .{ .name = "name" },86 .one_of = .{ .name = "name" },
87 };87 };
88 _ = &param;
88 var arg: CallArg = .{89 var arg: CallArg = .{
89 .value = .{90 .value = .{
90 .literal_enum_value = .{91 .literal_enum_value = .{
...@@ -92,6 +93,7 @@ test {...@@ -92,6 +93,7 @@ test {
92 },93 },
93 },94 },
94 };95 };
96 _ = &arg;
9597
96 const result = try genExpression(arg.value);98 const result = try genExpression(arg.value);
97 switch (result) {99 switch (result) {
test/behavior/bugs/9584.zig+1
...@@ -60,6 +60,7 @@ test {...@@ -60,6 +60,7 @@ test {
60 .g = false,60 .g = false,
61 .h = false,61 .h = false,
62 };62 };
63 _ = &flags;
63 var x = X{64 var x = X{
64 .x = flags,65 .x = flags,
65 };66 };
test/behavior/byteswap.zig+8-4
...@@ -56,7 +56,8 @@ test "@byteSwap integers" {...@@ -56,7 +56,8 @@ test "@byteSwap integers" {
5656
57fn vector8() !void {57fn vector8() !void {
58 var v = @Vector(2, u8){ 0x12, 0x13 };58 var v = @Vector(2, u8){ 0x12, 0x13 };
59 var result = @byteSwap(v);59 _ = &v;
60 const result = @byteSwap(v);
60 try expect(result[0] == 0x12);61 try expect(result[0] == 0x12);
61 try expect(result[1] == 0x13);62 try expect(result[1] == 0x13);
62}63}
...@@ -75,7 +76,8 @@ test "@byteSwap vectors u8" {...@@ -75,7 +76,8 @@ test "@byteSwap vectors u8" {
7576
76fn vector16() !void {77fn vector16() !void {
77 var v = @Vector(2, u16){ 0x1234, 0x2345 };78 var v = @Vector(2, u16){ 0x1234, 0x2345 };
78 var result = @byteSwap(v);79 _ = &v;
80 const result = @byteSwap(v);
79 try expect(result[0] == 0x3412);81 try expect(result[0] == 0x3412);
80 try expect(result[1] == 0x4523);82 try expect(result[1] == 0x4523);
81}83}
...@@ -94,7 +96,8 @@ test "@byteSwap vectors u16" {...@@ -94,7 +96,8 @@ test "@byteSwap vectors u16" {
9496
95fn vector24() !void {97fn vector24() !void {
96 var v = @Vector(2, u24){ 0x123456, 0x234567 };98 var v = @Vector(2, u24){ 0x123456, 0x234567 };
97 var result = @byteSwap(v);99 _ = &v;
100 const result = @byteSwap(v);
98 try expect(result[0] == 0x563412);101 try expect(result[0] == 0x563412);
99 try expect(result[1] == 0x674523);102 try expect(result[1] == 0x674523);
100}103}
...@@ -113,7 +116,8 @@ test "@byteSwap vectors u24" {...@@ -113,7 +116,8 @@ test "@byteSwap vectors u24" {
113116
114fn vector0() !void {117fn vector0() !void {
115 var v = @Vector(2, u0){ 0, 0 };118 var v = @Vector(2, u0){ 0, 0 };
116 var result = @byteSwap(v);119 _ = &v;
120 const result = @byteSwap(v);
117 try expect(result[0] == 0);121 try expect(result[0] == 0);
118 try expect(result[1] == 0);122 try expect(result[1] == 0);
119}123}
test/behavior/call.zig+5
...@@ -47,6 +47,7 @@ test "basic invocations" {...@@ -47,6 +47,7 @@ test "basic invocations" {
47 {47 {
48 // call of non comptime-known function48 // call of non comptime-known function
49 var alias_foo = &foo;49 var alias_foo = &foo;
50 _ = &alias_foo;
50 try expect(@call(.no_async, alias_foo, .{}) == 1234);51 try expect(@call(.no_async, alias_foo, .{}) == 1234);
51 try expect(@call(.never_tail, alias_foo, .{}) == 1234);52 try expect(@call(.never_tail, alias_foo, .{}) == 1234);
52 try expect(@call(.never_inline, alias_foo, .{}) == 1234);53 try expect(@call(.never_inline, alias_foo, .{}) == 1234);
...@@ -66,6 +67,7 @@ test "tuple parameters" {...@@ -66,6 +67,7 @@ test "tuple parameters" {
66 }.add;67 }.add;
67 var a: i32 = 12;68 var a: i32 = 12;
68 var b: i32 = 34;69 var b: i32 = 34;
70 _ = .{ &a, &b };
69 try expect(@call(.auto, add, .{ a, 34 }) == 46);71 try expect(@call(.auto, add, .{ a, 34 }) == 46);
70 try expect(@call(.auto, add, .{ 12, b }) == 46);72 try expect(@call(.auto, add, .{ 12, b }) == 46);
71 try expect(@call(.auto, add, .{ a, b }) == 46);73 try expect(@call(.auto, add, .{ a, b }) == 46);
...@@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st...@@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st
101 }103 }
102 };104 };
103 var runtime = true;105 var runtime = true;
106 _ = &runtime;
104 try namespace.foo(.{107 try namespace.foo(.{
105 .e = if (!runtime) .a else .b,108 .e = if (!runtime) .a else .b,
106 });109 });
...@@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" {...@@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" {
445448
446 var rt_u16: u16 = 123;449 var rt_u16: u16 = 123;
447 var rt_u32: u32 = 0x10000222;450 var rt_u32: u32 = 0x10000222;
451 _ = .{ &rt_u16, &rt_u32 };
448452
449 try S.f(u8, @intCast(rt_u16));453 try S.f(u8, @intCast(rt_u16));
450 try S.f(u8, @intCast(123));454 try S.f(u8, @intCast(123));
...@@ -470,6 +474,7 @@ test "argument to generic function has correct result type" {...@@ -470,6 +474,7 @@ test "argument to generic function has correct result type" {
470474
471 fn doTheTest() !void {475 fn doTheTest() !void {
472 var t = true;476 var t = true;
477 _ = &t;
473478
474 // Since the enum literal passes through a runtime conditional here, these can only479 // Since the enum literal passes through a runtime conditional here, these can only
475 // compile if RLS provides the correct result type to the argument480 // compile if RLS provides the correct result type to the argument
test/behavior/cast.zig+118-42
...@@ -58,6 +58,7 @@ test "@intCast to comptime_int" {...@@ -58,6 +58,7 @@ test "@intCast to comptime_int" {
58test "implicit cast comptime numbers to any type when the value fits" {58test "implicit cast comptime numbers to any type when the value fits" {
59 const a: u64 = 255;59 const a: u64 = 255;
60 var b: u8 = a;60 var b: u8 = a;
61 _ = &b;
61 try expect(b == 255);62 try expect(b == 255);
62}63}
6364
...@@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" {...@@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" {
273274
274test "*usize to *void" {275test "*usize to *void" {
275 var i = @as(usize, 0);276 var i = @as(usize, 0);
276 var v = @as(*void, @ptrCast(&i));277 const v: *void = @ptrCast(&i);
277 v.* = {};278 v.* = {};
278}279}
279280
...@@ -391,7 +392,8 @@ test "peer type unsigned int to signed" {...@@ -391,7 +392,8 @@ test "peer type unsigned int to signed" {
391 var w: u31 = 5;392 var w: u31 = 5;
392 var x: u8 = 7;393 var x: u8 = 7;
393 var y: i32 = -5;394 var y: i32 = -5;
394 var a = w + y + x;395 _ = .{ &w, &x, &y };
396 const a = w + y + x;
395 try comptime expect(@TypeOf(a) == i32);397 try comptime expect(@TypeOf(a) == i32);
396 try expect(a == 7);398 try expect(a == 7);
397}399}
...@@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" {...@@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" {
401 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
402404
403 var a: [*:0]const u8 = "hello";405 var a: [*:0]const u8 = "hello";
404 var b: [*c]const u8 = a;406 _ = &a;
405 var c: [*:0]const u8 = b;407 const b: [*c]const u8 = a;
408 const c: [*:0]const u8 = b;
406 try expect(std.mem.eql(u8, c[0..5], "hello"));409 try expect(std.mem.eql(u8, c[0..5], "hello"));
407}410}
408411
...@@ -609,14 +612,16 @@ test "@intCast on vector" {...@@ -609,14 +612,16 @@ test "@intCast on vector" {
609 fn doTheTest() !void {612 fn doTheTest() !void {
610 // Upcast (implicit, equivalent to @intCast)613 // Upcast (implicit, equivalent to @intCast)
611 var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa };614 var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa };
612 var up1 = @as(@Vector(2, u16), up0);615 _ = &up0;
613 var up2 = @as(@Vector(2, u32), up0);616 const up1 = @as(@Vector(2, u16), up0);
614 var up3 = @as(@Vector(2, u64), up0);617 const up2 = @as(@Vector(2, u32), up0);
618 const up3 = @as(@Vector(2, u64), up0);
615 // Downcast (safety-checked)619 // Downcast (safety-checked)
616 var down0 = up3;620 var down0 = up3;
617 var down1 = @as(@Vector(2, u32), @intCast(down0));621 _ = &down0;
618 var down2 = @as(@Vector(2, u16), @intCast(down0));622 const down1 = @as(@Vector(2, u32), @intCast(down0));
619 var down3 = @as(@Vector(2, u8), @intCast(down0));623 const down2 = @as(@Vector(2, u16), @intCast(down0));
624 const down3 = @as(@Vector(2, u8), @intCast(down0));
620625
621 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));626 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
622 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));627 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
...@@ -629,7 +634,8 @@ test "@intCast on vector" {...@@ -629,7 +634,8 @@ test "@intCast on vector" {
629634
630 fn doTheTestFloat() !void {635 fn doTheTestFloat() !void {
631 var vec: @Vector(2, f32) = @splat(1234.0);636 var vec: @Vector(2, f32) = @splat(1234.0);
632 var wider: @Vector(2, f64) = vec;637 _ = &vec;
638 const wider: @Vector(2, f64) = vec;
633 try expect(wider[0] == 1234.0);639 try expect(wider[0] == 1234.0);
634 try expect(wider[1] == 1234.0);640 try expect(wider[1] == 1234.0);
635 }641 }
...@@ -648,7 +654,8 @@ test "@floatCast cast down" {...@@ -648,7 +654,8 @@ test "@floatCast cast down" {
648654
649 {655 {
650 var double: f64 = 0.001534;656 var double: f64 = 0.001534;
651 var single = @as(f32, @floatCast(double));657 _ = &double;
658 const single = @as(f32, @floatCast(double));
652 try expect(single == 0.001534);659 try expect(single == 0.001534);
653 }660 }
654 {661 {
...@@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" {...@@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" {
672 Unexpected,679 Unexpected,
673 };680 };
674 var err = Error.SystemResources;681 var err = Error.SystemResources;
682 _ = &err;
675 const transformed_err = switch (err) {683 const transformed_err = switch (err) {
676 error.FileDescriptorAlreadyPresentInSet => unreachable,684 error.FileDescriptorAlreadyPresentInSet => unreachable,
677 error.OperationCausesCircularLoop => unreachable,685 error.OperationCausesCircularLoop => unreachable,
...@@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" {...@@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" {
821 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO829 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
822830
823 var buffer: [5]u8 = "abcde".*;831 var buffer: [5]u8 = "abcde".*;
824 var buf: anyerror![]const u8 = buffer[0..];832 const buf: anyerror![]const u8 = buffer[0..];
825 var b = false;833 var b = false;
826 var y = if (b) &[0]u8{} else buf;834 _ = &b;
827 var z = if (!b) buf else &[0]u8{};835 const y = if (b) &[0]u8{} else buf;
836 const z = if (!b) buf else &[0]u8{};
828 try expect(mem.eql(u8, "abcde", y catch unreachable));837 try expect(mem.eql(u8, "abcde", y catch unreachable));
829 try expect(mem.eql(u8, "abcde", z catch unreachable));838 try expect(mem.eql(u8, "abcde", z catch unreachable));
830}839}
...@@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" {...@@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" {
835 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO844 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
836845
837 var buffer: [5]u8 = "abcde".*;846 var buffer: [5]u8 = "abcde".*;
838 var buf: []const u8 = buffer[0..];847 const buf: []const u8 = buffer[0..];
839 var b = false;848 var b = false;
840 var y = if (b) &[0]u8{} else buf;849 _ = &b;
850 const y = if (b) &[0]u8{} else buf;
841 try expect(mem.eql(u8, "abcde", y));851 try expect(mem.eql(u8, "abcde", y));
842}852}
843853
...@@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" {...@@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" {
846856
847 var array = [4:99]i32{ 1, 2, 3, 4 };857 var array = [4:99]i32{ 1, 2, 3, 4 };
848 var dest: [*]i32 = undefined;858 var dest: [*]i32 = undefined;
859 _ = &dest;
849 try expect(@TypeOf(&array, dest) == [*]i32);860 try expect(@TypeOf(&array, dest) == [*]i32);
850 try expect(@TypeOf(dest, &array) == [*]i32);861 try expect(@TypeOf(dest, &array) == [*]i32);
851}862}
...@@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" {...@@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" {
879 const S = struct {890 const S = struct {
880 fn doTheTest() !void {891 fn doTheTest() !void {
881 var array = [4:0]i32{ 1, 2, 3, 4 };892 var array = [4:0]i32{ 1, 2, 3, 4 };
882 var slice: [:0]i32 = &array;893 const slice: [:0]i32 = &array;
883 var dest: []i32 = slice;894 const dest: []i32 = slice;
884 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));895 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
885 }896 }
886 };897 };
...@@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" {...@@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" {
895 const S = struct {906 const S = struct {
896 fn doTheTest() !void {907 fn doTheTest() !void {
897 var array = [4:0]i32{ 1, 2, 3, 4 };908 var array = [4:0]i32{ 1, 2, 3, 4 };
898 var dest: [4]i32 = array;909 _ = &array;
910 const dest: [4]i32 = array;
899 try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));911 try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
900 }912 }
901 };913 };
...@@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" {...@@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" {
910 const S = struct {922 const S = struct {
911 fn doTheTest() !void {923 fn doTheTest() !void {
912 var array = [4:0]i32{ 1, 2, 3, 4 };924 var array = [4:0]i32{ 1, 2, 3, 4 };
913 var dest: *[4]i32 = &array;925 const dest: *[4]i32 = &array;
914 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));926 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
915 }927 }
916 };928 };
...@@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" {...@@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" {
925 const S = struct {937 const S = struct {
926 fn doTheTest() !void {938 fn doTheTest() !void {
927 var array = [4:99]i32{ 1, 2, 3, 4 };939 var array = [4:99]i32{ 1, 2, 3, 4 };
928 var dest: [*]i32 = &array;940 const dest: [*]i32 = &array;
929 try expect(dest[0] == 1);941 try expect(dest[0] == 1);
930 try expect(dest[1] == 2);942 try expect(dest[1] == 2);
931 try expect(dest[2] == 3);943 try expect(dest[2] == 3);
...@@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" {...@@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" {
945 const S = struct {957 const S = struct {
946 fn doTheTest() !void {958 fn doTheTest() !void {
947 var array = [4:0]i32{ 1, 2, 3, 4 };959 var array = [4:0]i32{ 1, 2, 3, 4 };
948 var slice: [:0]i32 = &array;960 const slice: [:0]i32 = &array;
949 var dest: [*:0]i32 = slice;961 const dest: [*:0]i32 = slice;
950 try expect(dest[0] == 1);962 try expect(dest[0] == 1);
951 try expect(dest[1] == 2);963 try expect(dest[1] == 2);
952 try expect(dest[2] == 3);964 try expect(dest[2] == 3);
...@@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" {...@@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" {
9981010
999test "variable initialization uses result locations properly with regards to the type" {1011test "variable initialization uses result locations properly with regards to the type" {
1000 var b = true;1012 var b = true;
1013 _ = &b;
1001 const x: i32 = if (b) 1 else 2;1014 const x: i32 = if (b) 1 else 2;
1002 try expect(x == 1);1015 try expect(x == 1);
1003}1016}
...@@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {...@@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {
10251038
1026 var array: [4:0]u8 = undefined;1039 var array: [4:0]u8 = undefined;
1027 array[4] = 0; // TODO remove this when #4372 is solved1040 array[4] = 0; // TODO remove this when #4372 is solved
1028 var slice: [:0]u8 = array[0..4 :0];1041 const slice: [:0]u8 = array[0..4 :0];
1029 try comptime expect(@TypeOf(slice, "hi") == [:0]const u8);1042 try comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
1030 try comptime expect(@TypeOf("hi", slice) == [:0]const u8);1043 try comptime expect(@TypeOf("hi", slice) == [:0]const u8);
1031}1044}
...@@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" {...@@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" {
1042 var array: [4]u8 = undefined;1055 var array: [4]u8 = undefined;
1043 var const_ptr: [*]const u8 = undefined;1056 var const_ptr: [*]const u8 = undefined;
1044 var ptr: [*]u8 = undefined;1057 var ptr: [*]u8 = undefined;
1058 _ = .{ &const_ptr, &ptr };
10451059
1046 try comptime expect(@TypeOf(&array, ptr) == [*]u8);1060 try comptime expect(@TypeOf(&array, ptr) == [*]u8);
1047 try comptime expect(@TypeOf(ptr, &array) == [*]u8);1061 try comptime expect(@TypeOf(ptr, &array) == [*]u8);
...@@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" {...@@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" {
10901104
1091 var a = [_]u8{ 3, 2, 1 };1105 var a = [_]u8{ 3, 2, 1 };
1092 var runtime_zero: usize = 0;1106 var runtime_zero: usize = 0;
1107 _ = &runtime_zero;
1093 incrementVoidPtrArray(a[runtime_zero..].ptr, 3);1108 incrementVoidPtrArray(a[runtime_zero..].ptr, 3);
1094 try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));1109 try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
1095}1110}
...@@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" {...@@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" {
1151 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1166 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
11521167
1153 var a: u32 = 1;1168 var a: u32 = 1;
1154 var ptr: *align(@alignOf(u32)) anyopaque = &a;1169 const ptr: *align(@alignOf(u32)) anyopaque = &a;
1155 var b: *u32 = @as(*u32, @ptrCast(ptr));1170 const b: *u32 = @as(*u32, @ptrCast(ptr));
1156 try expect(b.* == 1);1171 try expect(b.* == 1);
1157 var ptr2: ?*align(@alignOf(u32)) anyopaque = &a;1172 const ptr2: ?*align(@alignOf(u32)) anyopaque = &a;
1158 var c: *u32 = @as(*u32, @ptrCast(ptr2.?));1173 const c: *u32 = @as(*u32, @ptrCast(ptr2.?));
1159 try expect(c.* == 1);1174 try expect(c.* == 1);
1160}1175}
11611176
...@@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" {...@@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" {
1264 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1279 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
12651280
1266 var x = @as(anyerror![]const u8, &[0]u8{});1281 var x = @as(anyerror![]const u8, &[0]u8{});
1282 _ = &x;
1267 try expect((x catch unreachable).len == 0);1283 try expect((x catch unreachable).len == 0);
1268}1284}
12691285
...@@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" {...@@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" {
1274}1290}
1275test "cast from array reference to fn: runtime fn ptr" {1291test "cast from array reference to fn: runtime fn ptr" {
1276 var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));1292 var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
1293 _ = &f;
1277 try expect(@intFromPtr(f) == @intFromPtr(&global_array));1294 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
1278}1295}
12791296
...@@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" {...@@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" {
1285 const S = struct {1302 const S = struct {
1286 fn doTheTest() !void {1303 fn doTheTest() !void {
1287 var a = "Hello";1304 var a = "Hello";
1288 var b: ?[]const u8 = a;1305 _ = &a;
1306 const b: ?[]const u8 = a;
1289 try expect(mem.eql(u8, b.?, "Hello"));1307 try expect(mem.eql(u8, b.?, "Hello"));
1290 }1308 }
1291 };1309 };
...@@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" {...@@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" {
1318 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1336 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
13191337
1320 var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct };1338 var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct };
1339 _ = &foo;
1321 try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct)));1340 try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct)));
1322}1341}
13231342
1324test "cast between *[N]void and []void" {1343test "cast between *[N]void and []void" {
1325 var a: [4]void = undefined;1344 var a: [4]void = undefined;
1326 var b: []void = &a;1345 const b: []void = &a;
1327 try expect(b.len == 4);1346 try expect(b.len == 4);
1328}1347}
13291348
...@@ -1351,6 +1370,7 @@ test "cast f16 to wider types" {...@@ -1351,6 +1370,7 @@ test "cast f16 to wider types" {
1351 const S = struct {1370 const S = struct {
1352 fn doTheTest() !void {1371 fn doTheTest() !void {
1353 var x: f16 = 1234.0;1372 var x: f16 = 1234.0;
1373 _ = &x;
1354 try expect(@as(f32, 1234.0) == x);1374 try expect(@as(f32, 1234.0) == x);
1355 try expect(@as(f64, 1234.0) == x);1375 try expect(@as(f64, 1234.0) == x);
1356 try expect(@as(f128, 1234.0) == x);1376 try expect(@as(f128, 1234.0) == x);
...@@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" {...@@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" {
1370 const S = struct {1390 const S = struct {
1371 fn doTheTest() !void {1391 fn doTheTest() !void {
1372 var x: f128 = 1234.0;1392 var x: f128 = 1234.0;
1393 _ = &x;
1373 try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x)));1394 try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x)));
1374 try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x)));1395 try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x)));
1375 try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x)));1396 try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x)));
...@@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" {...@@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" {
1404 const S = struct {1425 const S = struct {
1405 fn doTheTest() !void {1426 fn doTheTest() !void {
1406 var cond = true;1427 var cond = true;
1428 _ = &cond;
1407 const value: i32 = if (cond) smallBoi() else bigBoi();1429 const value: i32 = if (cond) smallBoi() else bigBoi();
1408 try expect(value == 123);1430 try expect(value == 123);
1409 }1431 }
...@@ -1424,7 +1446,8 @@ test "cast compatible optional types" {...@@ -1424,7 +1446,8 @@ test "cast compatible optional types" {
1424 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1446 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14251447
1426 var a: ?[:0]const u8 = null;1448 var a: ?[:0]const u8 = null;
1427 var b: ?[]const u8 = a;1449 _ = &a;
1450 const b: ?[]const u8 = a;
1428 try expect(b == null);1451 try expect(b == null);
1429}1452}
14301453
...@@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" {...@@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" {
14341457
1435 const a = @as([*]u8, undefined)[0..0];1458 const a = @as([*]u8, undefined)[0..0];
1436 var b: error{a}![]const u8 = a;1459 var b: error{a}![]const u8 = a;
1460 _ = &b;
1437 const s = try b;1461 const s = try b;
1438 try expect(s.len == 0);1462 try expect(s.len == 0);
1439}1463}
...@@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" {...@@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" {
1442 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1466 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14431467
1444 var x: []i32 = &.{};1468 var x: []i32 = &.{};
1469 _ = &x;
1445 try expect(x.len == 0);1470 try expect(x.len == 0);
1446}1471}
14471472
...@@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" {...@@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" {
1466 else => @compileError("unreachable"),1491 else => @compileError("unreachable"),
1467 };1492 };
1468 var f1: F = 12.34;1493 var f1: F = 12.34;
1469 var f2: *c_longdouble = &f1;1494 const f2: *c_longdouble = &f1;
1470 f2.* += 1;1495 f2.* += 1;
1471 try expect(f1 == @as(F, 12.34) + 1);1496 try expect(f1 == @as(F, 12.34) + 1);
1472}1497}
...@@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" {...@@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" {
1507 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1532 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
15081533
1509 var a: [:0]const u8 = "foo";1534 var a: [:0]const u8 = "foo";
1510 var b: [*c]const u8 = a;1535 _ = &a;
1511 var c = std.mem.span(b);1536 const b: [*c]const u8 = a;
1537 const c = std.mem.span(b);
1512 try expect(c.len == a.len);1538 try expect(c.len == a.len);
1513 try expect(c.ptr == a.ptr);1539 try expect(c.ptr == a.ptr);
1514}1540}
...@@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" {...@@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" {
15441570
1545test "peer type resolution forms error union" {1571test "peer type resolution forms error union" {
1546 var foo: i32 = 123;1572 var foo: i32 = 123;
1573 _ = &foo;
1547 const result = if (foo < 0) switch (-foo) {1574 const result = if (foo < 0) switch (-foo) {
1548 0 => unreachable,1575 0 => unreachable,
1549 42 => error.AccessDenied,1576 42 => error.AccessDenied,
...@@ -1561,7 +1588,7 @@ test "@constCast without a result location" {...@@ -1561,7 +1588,7 @@ test "@constCast without a result location" {
15611588
1562test "@volatileCast without a result location" {1589test "@volatileCast without a result location" {
1563 var x: i32 = 1234;1590 var x: i32 = 1234;
1564 var y: *volatile i32 = &x;1591 const y: *volatile i32 = &x;
1565 const z = @volatileCast(y);1592 const z = @volatileCast(y);
1566 try expect(@TypeOf(z) == *i32);1593 try expect(@TypeOf(z) == *i32);
1567 try expect(z.* == 1234);1594 try expect(z.* == 1234);
...@@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"...@@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
1585 fn doTheTest(comptime T: type, comptime s: T) !void {1612 fn doTheTest(comptime T: type, comptime s: T) !void {
1586 var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000));1613 var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000));
1587 var b: []T = @as(*[3]T, @ptrFromInt(0x2000));1614 var b: []T = @as(*[3]T, @ptrFromInt(0x2000));
1615 _ = .{ &a, &b };
1588 comptime assert(@TypeOf(a, b) == []const T);1616 comptime assert(@TypeOf(a, b) == []const T);
1589 comptime assert(@TypeOf(b, a) == []const T);1617 comptime assert(@TypeOf(b, a) == []const T);
15901618
1591 var t = true;1619 var t = true;
1620 _ = &t;
1592 const r1 = if (t) a else b;1621 const r1 = if (t) a else b;
1593 const r2 = if (t) b else a;1622 const r2 = if (t) b else a;
15941623
...@@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" {...@@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" {
16111640
1612 const i: u8 = 100;1641 const i: u8 = 100;
1613 var f: f32 = 1.234;1642 var f: f32 = 1.234;
1643 _ = &f;
1614 comptime assert(@TypeOf(i, f) == f32);1644 comptime assert(@TypeOf(i, f) == f32);
1615 comptime assert(@TypeOf(f, i) == f32);1645 comptime assert(@TypeOf(f, i) == f32);
16161646
1617 var t = true;1647 var t = true;
1648 _ = &t;
1618 const r1 = if (t) i else f;1649 const r1 = if (t) i else f;
1619 const r2 = if (t) f else i;1650 const r2 = if (t) f else i;
16201651
...@@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" {...@@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" {
16311662
1632 var a: [2:0]u32 = .{ 0, 1 };1663 var a: [2:0]u32 = .{ 0, 1 };
1633 var b: [2:0]u32 = .{ 2, 3 };1664 var b: [2:0]u32 = .{ 2, 3 };
1665 _ = .{ &a, &b };
1634 comptime assert(@TypeOf(a, b) == [2:0]u32);1666 comptime assert(@TypeOf(a, b) == [2:0]u32);
1635 comptime assert(@TypeOf(b, a) == [2:0]u32);1667 comptime assert(@TypeOf(b, a) == [2:0]u32);
16361668
1637 var t = true;1669 var t = true;
1670 _ = &t;
1638 const r1 = if (t) a else b;1671 const r1 = if (t) a else b;
1639 const r2 = if (t) b else a;1672 const r2 = if (t) b else a;
16401673
...@@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" {...@@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" {
16511684
1652 var a: [2:0]u32 = .{ 0, 1 };1685 var a: [2:0]u32 = .{ 0, 1 };
1653 var b: [2]u32 = .{ 2, 3 };1686 var b: [2]u32 = .{ 2, 3 };
1687 _ = .{ &a, &b };
1654 comptime assert(@TypeOf(a, b) == [2]u32);1688 comptime assert(@TypeOf(a, b) == [2]u32);
1655 comptime assert(@TypeOf(b, a) == [2]u32);1689 comptime assert(@TypeOf(b, a) == [2]u32);
16561690
1657 var t = true;1691 var t = true;
1692 _ = &t;
1658 const r1 = if (t) a else b;1693 const r1 = if (t) a else b;
1659 const r2 = if (t) b else a;1694 const r2 = if (t) b else a;
16601695
...@@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" {...@@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" {
16711706
1672 var arr: [2]u32 = .{ 0, 1 };1707 var arr: [2]u32 = .{ 0, 1 };
1673 var vec: @Vector(2, u32) = .{ 2, 3 };1708 var vec: @Vector(2, u32) = .{ 2, 3 };
1709 _ = .{ &arr, &vec };
1674 comptime assert(@TypeOf(arr, vec) == @Vector(2, u32));1710 comptime assert(@TypeOf(arr, vec) == @Vector(2, u32));
1675 comptime assert(@TypeOf(vec, arr) == @Vector(2, u32));1711 comptime assert(@TypeOf(vec, arr) == @Vector(2, u32));
16761712
1677 var t = true;1713 var t = true;
1714 _ = &t;
1678 const r1 = if (t) arr else vec;1715 const r1 = if (t) arr else vec;
1679 const r2 = if (t) vec else arr;1716 const r2 = if (t) vec else arr;
16801717
...@@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger...@@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger
16941731
1695 var arr: [2]u8 = .{ 0, 1 };1732 var arr: [2]u8 = .{ 0, 1 };
1696 var vec: @Vector(2, u64) = .{ 2, 3 };1733 var vec: @Vector(2, u64) = .{ 2, 3 };
1734 _ = .{ &arr, &vec };
1697 comptime assert(@TypeOf(arr, vec) == @Vector(2, u64));1735 comptime assert(@TypeOf(arr, vec) == @Vector(2, u64));
1698 comptime assert(@TypeOf(vec, arr) == @Vector(2, u64));1736 comptime assert(@TypeOf(vec, arr) == @Vector(2, u64));
16991737
1700 var t = true;1738 var t = true;
1739 _ = &t;
1701 const r1 = if (t) arr else vec;1740 const r1 = if (t) arr else vec;
1702 const r2 = if (t) vec else arr;1741 const r2 = if (t) vec else arr;
17031742
...@@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" {...@@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" {
1715 const E = error{Foo};1754 const E = error{Foo};
1716 var a: E!*u8 = error.Foo;1755 var a: E!*u8 = error.Foo;
1717 var b: ?*u8 = null;1756 var b: ?*u8 = null;
1757 _ = .{ &a, &b };
1718 comptime assert(@TypeOf(a, b) == E!?*u8);1758 comptime assert(@TypeOf(a, b) == E!?*u8);
1719 comptime assert(@TypeOf(b, a) == E!?*u8);1759 comptime assert(@TypeOf(b, a) == E!?*u8);
17201760
1721 var t = true;1761 var t = true;
1762 _ = &t;
1722 const r1 = if (t) a else b;1763 const r1 = if (t) a else b;
1723 const r2 = if (t) b else a;1764 const r2 = if (t) b else a;
17241765
...@@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" {...@@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" {
1734 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1775 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
17351776
1736 var a: [*c]c_int = 0x1000;1777 var a: [*c]c_int = 0x1000;
1778 _ = &a;
1737 const b = null;1779 const b = null;
1738 comptime assert(@TypeOf(a, b) == [*c]c_int);1780 comptime assert(@TypeOf(a, b) == [*c]c_int);
1739 comptime assert(@TypeOf(b, a) == [*c]c_int);1781 comptime assert(@TypeOf(b, a) == [*c]c_int);
17401782
1741 var t = true;1783 var t = true;
1784 _ = &t;
1742 const r1 = if (t) a else b;1785 const r1 = if (t) a else b;
1743 const r2 = if (t) b else a;1786 const r2 = if (t) b else a;
17441787
...@@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional...@@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional
17551798
1756 const E = error{Foo};1799 const E = error{Foo};
1757 var a: E = error.Foo;1800 var a: E = error.Foo;
1758 var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000));1801 var b: *const [5:0]u8 = @ptrFromInt(0x1000);
1759 var c: ?[*:0]u8 = null;1802 var c: ?[*:0]u8 = null;
1803 _ = .{ &a, &b, &c };
1760 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);1804 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);
1761 comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8);1805 comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8);
1762 comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8);1806 comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8);
...@@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional...@@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional
1765 comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8);1809 comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8);
17661810
1767 var x: u8 = 0;1811 var x: u8 = 0;
1812 _ = &x;
1768 const r1 = switch (x) {1813 const r1 = switch (x) {
1769 0 => a,1814 0 => a,
1770 1 => b,1815 1 => b,
...@@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" {...@@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" {
17971842
1798 var a: ?@Vector(3, u32) = .{ 0, 1, 2 };1843 var a: ?@Vector(3, u32) = .{ 0, 1, 2 };
1799 var b: @Vector(3, u32) = .{ 3, 4, 5 };1844 var b: @Vector(3, u32) = .{ 3, 4, 5 };
1845 _ = .{ &a, &b };
1800 comptime assert(@TypeOf(a, b) == ?@Vector(3, u32));1846 comptime assert(@TypeOf(a, b) == ?@Vector(3, u32));
1801 comptime assert(@TypeOf(b, a) == ?@Vector(3, u32));1847 comptime assert(@TypeOf(b, a) == ?@Vector(3, u32));
18021848
1803 var t = true;1849 var t = true;
1850 _ = &t;
1804 const r1 = if (t) a else b;1851 const r1 = if (t) a else b;
1805 const r2 = if (t) b else a;1852 const r2 = if (t) b else a;
18061853
...@@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" {...@@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" {
1816 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1863 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18171864
1818 var a: ?i32 = 42;1865 var a: ?i32 = 42;
1866 _ = &a;
1819 const b: comptime_int = 50;1867 const b: comptime_int = 50;
1820 comptime assert(@TypeOf(a, b) == ?i32);1868 comptime assert(@TypeOf(a, b) == ?i32);
1821 comptime assert(@TypeOf(b, a) == ?i32);1869 comptime assert(@TypeOf(b, a) == ?i32);
18221870
1823 var t = true;1871 var t = true;
1872 _ = &t;
1824 const r1 = if (t) a else b;1873 const r1 = if (t) a else b;
1825 const r2 = if (t) b else a;1874 const r2 = if (t) b else a;
18261875
...@@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" {...@@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" {
1836 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1885 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18371886
1838 var arr: [3]i32 = .{ 1, 2, 3 };1887 var arr: [3]i32 = .{ 1, 2, 3 };
1888 _ = &arr;
1839 const tup = .{ 4, 5, 6 };1889 const tup = .{ 4, 5, 6 };
18401890
1841 comptime assert(@TypeOf(arr, tup) == [3]i32);1891 comptime assert(@TypeOf(arr, tup) == [3]i32);
1842 comptime assert(@TypeOf(tup, arr) == [3]i32);1892 comptime assert(@TypeOf(tup, arr) == [3]i32);
18431893
1844 var t = true;1894 var t = true;
1895 _ = &t;
1845 const r1 = if (t) arr else tup;1896 const r1 = if (t) arr else tup;
1846 const r2 = if (t) tup else arr;1897 const r2 = if (t) tup else arr;
18471898
...@@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" {...@@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" {
1858 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1909 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18591910
1860 var vec: @Vector(3, i32) = .{ 1, 2, 3 };1911 var vec: @Vector(3, i32) = .{ 1, 2, 3 };
1912 _ = &vec;
1861 const tup = .{ 4, 5, 6 };1913 const tup = .{ 4, 5, 6 };
18621914
1863 comptime assert(@TypeOf(vec, tup) == @Vector(3, i32));1915 comptime assert(@TypeOf(vec, tup) == @Vector(3, i32));
1864 comptime assert(@TypeOf(tup, vec) == @Vector(3, i32));1916 comptime assert(@TypeOf(tup, vec) == @Vector(3, i32));
18651917
1866 var t = true;1918 var t = true;
1919 _ = &t;
1867 const r1 = if (t) vec else tup;1920 const r1 = if (t) vec else tup;
1868 const r2 = if (t) tup else vec;1921 const r2 = if (t) tup else vec;
18691922
...@@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" {...@@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" {
18811934
1882 var vec: @Vector(2, i8) = .{ 10, 20 };1935 var vec: @Vector(2, i8) = .{ 10, 20 };
1883 var arr: [2]i8 = .{ 30, 40 };1936 var arr: [2]i8 = .{ 30, 40 };
1937 _ = .{ &vec, &arr };
1884 const tup = .{ 50, 60 };1938 const tup = .{ 50, 60 };
18851939
1886 comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8));1940 comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8));
...@@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" {...@@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" {
1891 comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8));1945 comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8));
18921946
1893 var x: u8 = 0;1947 var x: u8 = 0;
1948 _ = &x;
1894 const r1 = switch (x) {1949 const r1 = switch (x) {
1895 0 => vec,1950 0 => vec,
1896 1 => arr,1951 1 => arr,
...@@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" {...@@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" {
19211976
1922 var a: [:0]const u8 = "Hello";1977 var a: [:0]const u8 = "Hello";
1923 var b = &.{};1978 var b = &.{};
1979 _ = .{ &a, &b };
19241980
1925 comptime assert(@TypeOf(a, b) == []const u8);1981 comptime assert(@TypeOf(a, b) == []const u8);
1926 comptime assert(@TypeOf(b, a) == []const u8);1982 comptime assert(@TypeOf(b, a) == []const u8);
19271983
1928 var t = true;1984 var t = true;
1985 _ = &t;
1929 const r1 = if (t) a else b;1986 const r1 = if (t) a else b;
1930 const r2 = if (t) b else a;1987 const r2 = if (t) b else a;
19311988
...@@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" {...@@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" {
19401997
1941 var a: [:0]const u8 = "Hello";1998 var a: [:0]const u8 = "Hello";
1942 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };1999 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };
2000 _ = .{ &a, &b };
19432001
1944 comptime assert(@TypeOf(a, b) == []const u8);2002 comptime assert(@TypeOf(a, b) == []const u8);
1945 comptime assert(@TypeOf(b, a) == []const u8);2003 comptime assert(@TypeOf(b, a) == []const u8);
19462004
1947 var t = true;2005 var t = true;
2006 _ = &t;
1948 const r1 = if (t) a else b;2007 const r1 = if (t) a else b;
1949 const r2 = if (t) b else a;2008 const r2 = if (t) b else a;
19502009
...@@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" {...@@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" {
19592018
1960 var a: ?[:0]const u8 = null;2019 var a: ?[:0]const u8 = null;
1961 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };2020 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };
2021 _ = .{ &a, &b };
19622022
1963 comptime assert(@TypeOf(a, b) == ?[]const u8);2023 comptime assert(@TypeOf(a, b) == ?[]const u8);
1964 comptime assert(@TypeOf(b, a) == ?[]const u8);2024 comptime assert(@TypeOf(b, a) == ?[]const u8);
19652025
1966 var t = true;2026 var t = true;
2027 _ = &t;
1967 const r1 = if (t) a else b;2028 const r1 = if (t) a else b;
1968 const r2 = if (t) b else a;2029 const r2 = if (t) b else a;
19692030
...@@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" {...@@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" {
1986 @as([*]u8, &buf),2047 @as([*]u8, &buf),
1987 @as(*const [5]u8, "foo-4"),2048 @as(*const [5]u8, "foo-4"),
1988 };2049 };
2050 _ = &vals;
19892051
1990 // Check every possible permutation of types in @TypeOf2052 // Check every possible permutation of types in @TypeOf
1991 @setEvalBranchQuota(5000);2053 @setEvalBranchQuota(5000);
...@@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" {...@@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" {
2015 comptime assert(perms == 5 * 4 * 3 * 2 * 1);2077 comptime assert(perms == 5 * 4 * 3 * 2 * 1);
20162078
2017 var x: u8 = 0;2079 var x: u8 = 0;
2080 _ = &x;
2018 inline for (0..5) |i| {2081 inline for (0..5) |i| {
2019 const r = switch (x) {2082 const r = switch (x) {
2020 0 => vals[i],2083 0 => vals[i],
...@@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" {...@@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" {
2057 }2120 }
20582121
2059 var t = true;2122 var t = true;
2123 _ = &t;
2060 const r1 = if (t) a else b;2124 const r1 = if (t) a else b;
2061 const r2 = if (t) b else a;2125 const r2 = if (t) b else a;
20622126
...@@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" {...@@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" {
20742138
2075 var buf = "hello".*;2139 var buf = "hello".*;
20762140
2077 var a: [*c]u8 = &buf;2141 const a: [*c]u8 = &buf;
2078 var b: [*:0]const u8 = "world";2142 var b: [*:0]const u8 = "world";
2143 _ = &b;
20792144
2080 comptime assert(@TypeOf(a, b) == [*c]const u8);2145 comptime assert(@TypeOf(a, b) == [*c]const u8);
2081 comptime assert(@TypeOf(b, a) == [*c]const u8);2146 comptime assert(@TypeOf(b, a) == [*c]const u8);
20822147
2083 var t = true;2148 var t = true;
2149 _ = &t;
2084 const r1 = if (t) a else b;2150 const r1 = if (t) a else b;
2085 const r2 = if (t) b else a;2151 const r2 = if (t) b else a;
20862152
...@@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" {...@@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" {
2097 var buf_b align(4) = "bar".*;2163 var buf_b align(4) = "bar".*;
2098 var buf_c align(4) = "baz".*;2164 var buf_c align(4) = "baz".*;
20992165
2100 var a: [*:0]align(4) const u8 = &buf_a;2166 const a: [*:0]align(4) const u8 = &buf_a;
2101 var b: *align(2) volatile [3:0]u8 = &buf_b;2167 const b: *align(2) volatile [3:0]u8 = &buf_b;
2102 var c: [*:0]align(4) u8 = &buf_c;2168 const c: [*:0]align(4) u8 = &buf_c;
21032169
2104 comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8);2170 comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8);
2105 comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8);2171 comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8);
...@@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" {...@@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" {
2109 comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8);2175 comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8);
21102176
2111 var x: u8 = 0;2177 var x: u8 = 0;
2178 _ = &x;
2112 const r1 = switch (x) {2179 const r1 = switch (x) {
2113 0 => a,2180 0 => a,
2114 1 => b,2181 1 => b,
...@@ -2254,6 +2321,7 @@ test "@floatCast on vector" {...@@ -2254,6 +2321,7 @@ test "@floatCast on vector" {
2254 const S = struct {2321 const S = struct {
2255 fn doTheTest() !void {2322 fn doTheTest() !void {
2256 var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 };2323 var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 };
2324 _ = &a;
2257 const b: @Vector(3, f32) = @floatCast(a);2325 const b: @Vector(3, f32) = @floatCast(a);
2258 try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b);2326 try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b);
2259 }2327 }
...@@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" {...@@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" {
2274 const S = struct {2342 const S = struct {
2275 fn doTheTest() !void {2343 fn doTheTest() !void {
2276 var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 };2344 var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 };
2345 _ = &a;
2277 const b: @Vector(3, *anyopaque) = @ptrFromInt(a);2346 const b: @Vector(3, *anyopaque) = @ptrFromInt(a);
2278 try expectEqual(@Vector(3, *anyopaque){2347 try expectEqual(@Vector(3, *anyopaque){
2279 @ptrFromInt(0x1000),2348 @ptrFromInt(0x1000),
...@@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" {...@@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" {
2302 @ptrFromInt(0x2000),2371 @ptrFromInt(0x2000),
2303 @ptrFromInt(0x3000),2372 @ptrFromInt(0x3000),
2304 };2373 };
2374 _ = &a;
2305 const b: @Vector(3, usize) = @intFromPtr(a);2375 const b: @Vector(3, usize) = @intFromPtr(a);
2306 try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b);2376 try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b);
2307 }2377 }
...@@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" {...@@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" {
2322 const S = struct {2392 const S = struct {
2323 fn doTheTest() !void {2393 fn doTheTest() !void {
2324 var a: @Vector(3, u32) = .{ 10, 20, 30 };2394 var a: @Vector(3, u32) = .{ 10, 20, 30 };
2395 _ = &a;
2325 const b: @Vector(3, f32) = @floatFromInt(a);2396 const b: @Vector(3, f32) = @floatFromInt(a);
2326 try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b);2397 try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b);
2327 }2398 }
...@@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" {...@@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" {
2342 const S = struct {2413 const S = struct {
2343 fn doTheTest() !void {2414 fn doTheTest() !void {
2344 var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 };2415 var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 };
2416 _ = &a;
2345 const b: @Vector(3, u32) = @intFromFloat(a);2417 const b: @Vector(3, u32) = @intFromFloat(a);
2346 try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b);2418 try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b);
2347 }2419 }
...@@ -2362,6 +2434,7 @@ test "@intFromBool on vector" {...@@ -2362,6 +2434,7 @@ test "@intFromBool on vector" {
2362 const S = struct {2434 const S = struct {
2363 fn doTheTest() !void {2435 fn doTheTest() !void {
2364 var a: @Vector(3, bool) = .{ false, true, false };2436 var a: @Vector(3, bool) = .{ false, true, false };
2437 _ = &a;
2365 const b: @Vector(3, u1) = @intFromBool(a);2438 const b: @Vector(3, u1) = @intFromBool(a);
2366 try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b);2439 try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b);
2367 }2440 }
...@@ -2385,7 +2458,8 @@ test "15-bit int to float" {...@@ -2385,7 +2458,8 @@ test "15-bit int to float" {
2385 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;2458 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
23862459
2387 var a: u15 = 42;2460 var a: u15 = 42;
2388 var b: f32 = @floatFromInt(a);2461 _ = &a;
2462 const b: f32 = @floatFromInt(a);
2389 try expect(b == 42.0);2463 try expect(b == 42.0);
2390}2464}
23912465
...@@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" {...@@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" {
2417 const T = *const ?E!struct { x: ?*const E!?u8 };2491 const T = *const ?E!struct { x: ?*const E!?u8 };
24182492
2419 var val: T = &.{ .x = &@truncate(0x1234) };2493 var val: T = &.{ .x = &@truncate(0x1234) };
2494 _ = &val;
24202495
2421 const struct_val = val.*.? catch unreachable;2496 const struct_val = val.*.? catch unreachable;
2422 const int_val = (struct_val.x.?.* catch unreachable).?;2497 const int_val = (struct_val.x.?.* catch unreachable).?;
...@@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" {...@@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" {
2439 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO2514 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
24402515
2441 var x: @Vector(4, i32) = .{ 1, 2, 3, 4 };2516 var x: @Vector(4, i32) = .{ 1, 2, 3, 4 };
2517 _ = &x;
2442 const y: @Vector(4, i8) = @intCast(x);2518 const y: @Vector(4, i8) = @intCast(x);
24432519
2444 try expect(y[0] == 1);2520 try expect(y[0] == 1);
test/behavior/cast_int.zig+17-2
...@@ -12,7 +12,8 @@ test "@intCast i32 to u7" {...@@ -12,7 +12,8 @@ test "@intCast i32 to u7" {
1212
13 var x: u128 = maxInt(u128);13 var x: u128 = maxInt(u128);
14 var y: i32 = 120;14 var y: i32 = 120;
15 var z = x >> @as(u7, @intCast(y));15 _ = .{ &x, &y };
16 const z = x >> @as(u7, @intCast(y));
16 try expect(z == 0xff);17 try expect(z == 0xff);
17}18}
1819
...@@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" {...@@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" {
2324
24 var x: i8 = -5;25 var x: i8 = -5;
25 var y: i32 = -5;26 var y: i32 = -5;
27 _ = .{ &x, &y };
26 try expect(y == x);28 try expect(y == x);
2729
28 var x2: i32 = -5;30 var x2: i32 = -5;
29 var y2: i8 = -5;31 var y2: i8 = -5;
32 _ = .{ &x2, &y2 };
30 try expect(y2 == @as(i8, @intCast(x2)));33 try expect(y2 == @as(i8, @intCast(x2)));
31}34}
3235
33test "coerce non byte-sized integers accross 32bits boundary" {36test "coerce non byte-sized integers accross 32bits boundary" {
34 {37 {
35 var v: u21 = 6417;38 var v: u21 = 6417;
39 _ = &v;
36 const a: u32 = v;40 const a: u32 = v;
37 const b: u64 = v;41 const b: u64 = v;
38 const c: u64 = a;42 const c: u64 = a;
39 var w: u64 = 0x1234567812345678;43 var w: u64 = 0x1234567812345678;
44 _ = &w;
40 const d: u21 = @truncate(w);45 const d: u21 = @truncate(w);
41 const e: u60 = d;46 const e: u60 = d;
42 try expectEqual(@as(u32, 6417), a);47 try expectEqual(@as(u32, 6417), a);
...@@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {...@@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
4853
49 {54 {
50 var v: u10 = 234;55 var v: u10 = 234;
56 _ = &v;
51 const a: u32 = v;57 const a: u32 = v;
52 const b: u64 = v;58 const b: u64 = v;
53 const c: u64 = a;59 const c: u64 = a;
54 var w: u64 = 0x1234567812345678;60 var w: u64 = 0x1234567812345678;
61 _ = &w;
55 const d: u10 = @truncate(w);62 const d: u10 = @truncate(w);
56 const e: u60 = d;63 const e: u60 = d;
57 try expectEqual(@as(u32, 234), a);64 try expectEqual(@as(u32, 234), a);
...@@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {...@@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
62 }69 }
63 {70 {
64 var v: u7 = 11;71 var v: u7 = 11;
72 _ = &v;
65 const a: u32 = v;73 const a: u32 = v;
66 const b: u64 = v;74 const b: u64 = v;
67 const c: u64 = a;75 const c: u64 = a;
68 var w: u64 = 0x1234567812345678;76 var w: u64 = 0x1234567812345678;
77 _ = &w;
69 const d: u7 = @truncate(w);78 const d: u7 = @truncate(w);
70 const e: u60 = d;79 const e: u60 = d;
71 try expectEqual(@as(u32, 11), a);80 try expectEqual(@as(u32, 11), a);
...@@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {...@@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
7786
78 {87 {
79 var v: i21 = -6417;88 var v: i21 = -6417;
89 _ = &v;
80 const a: i32 = v;90 const a: i32 = v;
81 const b: i64 = v;91 const b: i64 = v;
82 const c: i64 = a;92 const c: i64 = a;
83 var w: i64 = -12345;93 var w: i64 = -12345;
94 _ = &w;
84 const d: i21 = @intCast(w);95 const d: i21 = @intCast(w);
85 const e: i60 = d;96 const e: i60 = d;
86 try expectEqual(@as(i32, -6417), a);97 try expectEqual(@as(i32, -6417), a);
...@@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {...@@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
92103
93 {104 {
94 var v: i10 = -234;105 var v: i10 = -234;
106 _ = &v;
95 const a: i32 = v;107 const a: i32 = v;
96 const b: i64 = v;108 const b: i64 = v;
97 const c: i64 = a;109 const c: i64 = a;
98 var w: i64 = -456;110 var w: i64 = -456;
111 _ = &w;
99 const d: i10 = @intCast(w);112 const d: i10 = @intCast(w);
100 const e: i60 = d;113 const e: i60 = d;
101 try expectEqual(@as(i32, -234), a);114 try expectEqual(@as(i32, -234), a);
...@@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {...@@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
106 }119 }
107 {120 {
108 var v: i7 = -11;121 var v: i7 = -11;
122 _ = &v;
109 const a: i32 = v;123 const a: i32 = v;
110 const b: i64 = v;124 const b: i64 = v;
111 const c: i64 = a;125 const c: i64 = a;
112 var w: i64 = -42;126 var w: i64 = -42;
127 _ = &w;
113 const d: i7 = @intCast(w);128 const d: i7 = @intCast(w);
114 const e: i60 = d;129 const e: i60 = d;
115 try expectEqual(@as(i32, -11), a);130 try expectEqual(@as(i32, -11), a);
...@@ -152,7 +167,7 @@ test "load non byte-sized optional value" {...@@ -152,7 +167,7 @@ test "load non byte-sized optional value" {
152 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;167 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
153168
154 // note: this bug is triggered by the == operator, expectEqual will hide it169 // note: this bug is triggered by the == operator, expectEqual will hide it
155 var opt: ?Piece = try Piece.charToPiece('p');170 const opt: ?Piece = try Piece.charToPiece('p');
156 try expect(opt.?.type == .PAWN);171 try expect(opt.?.type == .PAWN);
157 try expect(opt.?.color == .BLACK);172 try expect(opt.?.color == .BLACK);
158173
test/behavior/comptime_memory.zig+1-1
...@@ -280,7 +280,7 @@ test "dance on linker values" {...@@ -280,7 +280,7 @@ test "dance on linker values" {
280 if (ptr_size > @sizeOf(Bits))280 if (ptr_size > @sizeOf(Bits))
281 try doTypePunBitsTest(&weird_ptr[1]);281 try doTypePunBitsTest(&weird_ptr[1]);
282282
283 var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr));283 const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr);
284284
285 var rebuilt_bytes: [ptr_size]u8 = undefined;285 var rebuilt_bytes: [ptr_size]u8 = undefined;
286 var i: usize = 0;286 var i: usize = 0;
test/behavior/destructure.zig+4
...@@ -7,6 +7,7 @@ test "simple destructure" {...@@ -7,6 +7,7 @@ test "simple destructure" {
7 fn doTheTest() !void {7 fn doTheTest() !void {
8 var x: u32 = undefined;8 var x: u32 = undefined;
9 x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 };9 x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 };
10 _ = &z;
1011
11 comptime assert(@TypeOf(y) == u16);12 comptime assert(@TypeOf(y) == u16);
1213
...@@ -25,6 +26,7 @@ test "destructure with comptime syntax" {...@@ -25,6 +26,7 @@ test "destructure with comptime syntax" {
25 fn doTheTest() void {26 fn doTheTest() void {
26 comptime var x: f32 = undefined;27 comptime var x: f32 = undefined;
27 comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var28 comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var
29 _ = &z;
2830
29 comptime assert(@TypeOf(y) == comptime_int);31 comptime assert(@TypeOf(y) == comptime_int);
30 comptime assert(@TypeOf(z) == comptime_int);32 comptime assert(@TypeOf(z) == comptime_int);
...@@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" {...@@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" {
112test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" {114test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" {
113 var z: u32 = undefined;115 var z: u32 = undefined;
114 var x: u8, const y, z = .{ 1, 2, 3 };116 var x: u8, const y, z = .{ 1, 2, 3 };
117 _ = &x;
115118
116 comptime assert(@TypeOf(y) == comptime_int);119 comptime assert(@TypeOf(y) == comptime_int);
117 comptime assert(y == 2);120 comptime assert(y == 2);
...@@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn...@@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn
122125
123test "destructure of tuple with comptime fields results in some comptime-known values" {126test "destructure of tuple with comptime fields results in some comptime-known values" {
124 var runtime: u32 = 42;127 var runtime: u32 = 42;
128 _ = &runtime;
125 const a, const b, const c, const d = .{ 123, runtime, 456, runtime };129 const a, const b, const c, const d = .{ 123, runtime, 456, runtime };
126130
127 // a, c are comptime-known131 // a, c are comptime-known
test/behavior/empty_union.zig+4
...@@ -5,12 +5,14 @@ const expect = std.testing.expect;...@@ -5,12 +5,14 @@ const expect = std.testing.expect;
5test "switch on empty enum" {5test "switch on empty enum" {
6 const E = enum {};6 const E = enum {};
7 var e: E = undefined;7 var e: E = undefined;
8 _ = &e;
8 switch (e) {}9 switch (e) {}
9}10}
1011
11test "switch on empty enum with a specified tag type" {12test "switch on empty enum with a specified tag type" {
12 const E = enum(u8) {};13 const E = enum(u8) {};
13 var e: E = undefined;14 var e: E = undefined;
15 _ = &e;
14 switch (e) {}16 switch (e) {}
15}17}
1618
...@@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" {...@@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" {
1921
20 const U = union(enum(u8)) {};22 const U = union(enum(u8)) {};
21 var u: U = undefined;23 var u: U = undefined;
24 _ = &u;
22 switch (u) {}25 switch (u) {}
23}26}
2427
...@@ -28,6 +31,7 @@ test "switch on empty tagged union" {...@@ -28,6 +31,7 @@ test "switch on empty tagged union" {
28 const E = enum {};31 const E = enum {};
29 const U = union(E) {};32 const U = union(E) {};
30 var u: U = undefined;33 var u: U = undefined;
34 _ = &u;
31 switch (u) {}35 switch (u) {}
32}36}
3337
test/behavior/enum.zig+11-4
...@@ -579,6 +579,7 @@ test "enum literal cast to enum" {...@@ -579,6 +579,7 @@ test "enum literal cast to enum" {
579579
580 var color1: Color = .Auto;580 var color1: Color = .Auto;
581 var color2 = Color.Auto;581 var color2 = Color.Auto;
582 _ = .{ &color1, &color2 };
582 try expect(color1 == color2);583 try expect(color1 == color2);
583}584}
584585
...@@ -663,7 +664,8 @@ test "empty non-exhaustive enum" {...@@ -663,7 +664,8 @@ test "empty non-exhaustive enum" {
663 const E = enum(u8) { _ };664 const E = enum(u8) { _ };
664665
665 fn doTheTest(y: u8) !void {666 fn doTheTest(y: u8) !void {
666 var e = @as(E, @enumFromInt(y));667 var e: E = @enumFromInt(y);
668 _ = &e;
667 try expect(switch (e) {669 try expect(switch (e) {
668 _ => true,670 _ => true,
669 });671 });
...@@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" {...@@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" {
858const State = enum { Start };860const State = enum { Start };
859test "switch on enum with one member is comptime-known" {861test "switch on enum with one member is comptime-known" {
860 var state = State.Start;862 var state = State.Start;
863 _ = &state;
861 switch (state) {864 switch (state) {
862 State.Start => return,865 State.Start => return,
863 }866 }
...@@ -917,7 +920,8 @@ test "enum literal casting to tagged union" {...@@ -917,7 +920,8 @@ test "enum literal casting to tagged union" {
917920
918 var t = true;921 var t = true;
919 var x: Arch = .x86_64;922 var x: Arch = .x86_64;
920 var y = if (t) x else .x86_64;923 _ = .{ &t, &x };
924 const y = if (t) x else .x86_64;
921 switch (y) {925 switch (y) {
922 .x86_64 => {},926 .x86_64 => {},
923 else => @panic("fail"),927 else => @panic("fail"),
...@@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" {...@@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" {
1031 B = 0,1035 B = 0,
1032 };1036 };
1033 var b = LocalFoo.B;1037 var b = LocalFoo.B;
1038 _ = &b;
1034 try expect(mem.eql(u8, @tagName(b), "B"));1039 try expect(mem.eql(u8, @tagName(b), "B"));
1035}1040}
10361041
...@@ -1055,6 +1060,7 @@ test "tag name with signed enum values" {...@@ -1055,6 +1060,7 @@ test "tag name with signed enum values" {
1055 delta = 65,1060 delta = 65,
1056 };1061 };
1057 var b = LocalFoo.bravo;1062 var b = LocalFoo.bravo;
1063 _ = &b;
1058 try expect(mem.eql(u8, @tagName(b), "bravo"));1064 try expect(mem.eql(u8, @tagName(b), "bravo"));
1059}1065}
10601066
...@@ -1135,13 +1141,13 @@ test "tag name functions are unique" {...@@ -1135,13 +1141,13 @@ test "tag name functions are unique" {
1135 const E = enum { a, b };1141 const E = enum { a, b };
1136 var b = E.a;1142 var b = E.a;
1137 var a = @tagName(b);1143 var a = @tagName(b);
1138 _ = a;1144 _ = .{ &a, &b };
1139 }1145 }
1140 {1146 {
1141 const E = enum { a, b, c, d, e, f };1147 const E = enum { a, b, c, d, e, f };
1142 var b = E.a;1148 var b = E.a;
1143 var a = @tagName(b);1149 var a = @tagName(b);
1144 _ = a;1150 _ = .{ &a, &b };
1145 }1151 }
1146}1152}
11471153
...@@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {...@@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {
1189test "runtime int to enum with one possible value" {1195test "runtime int to enum with one possible value" {
1190 const E = enum { one };1196 const E = enum { one };
1191 var runtime: usize = 0;1197 var runtime: usize = 0;
1198 _ = &runtime;
1192 if (@as(E, @enumFromInt(runtime)) != .one) {1199 if (@as(E, @enumFromInt(runtime)) != .one) {
1193 @compileError("test failed");1200 @compileError("test failed");
1194 }1201 }
test/behavior/error.zig+14-8
...@@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" {...@@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" {
102102
103 const S = struct {103 const S = struct {
104 fn errorable() !u64 {104 fn errorable() !u64 {
105 var x = @as(u64, try number());105 return @as(u64, try number());
106 return x;
107 }106 }
108107
109 fn number() anyerror!u32 {108 fn number() anyerror!u32 {
...@@ -119,7 +118,7 @@ test "debug info for optional error set" {...@@ -119,7 +118,7 @@ test "debug info for optional error set" {
119118
120 const SomeError = error{ Hello, Hello2 };119 const SomeError = error{ Hello, Hello2 };
121 var a_local_variable: ?SomeError = null;120 var a_local_variable: ?SomeError = null;
122 _ = a_local_variable;121 _ = &a_local_variable;
123}122}
124123
125test "implicit cast to optional to error union to return result loc" {124test "implicit cast to optional to error union to return result loc" {
...@@ -160,6 +159,7 @@ fn entry() void {...@@ -160,6 +159,7 @@ fn entry() void {
160159
161fn entryPtr() void {160fn entryPtr() void {
162 var ptr = &bar2;161 var ptr = &bar2;
162 _ = &ptr;
163 fooPtr(ptr);163 fooPtr(ptr);
164}164}
165165
...@@ -226,9 +226,9 @@ const Set1 = error{ A, B };...@@ -226,9 +226,9 @@ const Set1 = error{ A, B };
226const Set2 = error{ A, C };226const Set2 = error{ A, C };
227227
228fn testExplicitErrorSetCast(set1: Set1) !void {228fn testExplicitErrorSetCast(set1: Set1) !void {
229 var x = @as(Set2, @errorCast(set1));229 const x: Set2 = @errorCast(set1);
230 try expect(@TypeOf(x) == Set2);230 try expect(@TypeOf(x) == Set2);
231 var y = @as(Set1, @errorCast(x));231 const y: Set1 = @errorCast(x);
232 try expect(@TypeOf(y) == Set1);232 try expect(@TypeOf(y) == Set1);
233 try expect(y == error.A);233 try expect(y == error.A);
234}234}
...@@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" {...@@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" {
408 };408 };
409409
410 fn errorable() !i32 {410 fn errorable() !i32 {
411 var x: Foo = (try getFoo()) orelse return error.Other;411 const x: Foo = (try getFoo()) orelse return error.Other;
412 return x.a;412 return x.a;
413 }413 }
414414
415 fn errorable2() !i32 {415 fn errorable2() !i32 {
416 var x: Foo = (try getFoo2()) orelse return error.Other;416 const x: Foo = (try getFoo2()) orelse return error.Other;
417 return x.a;417 return x.a;
418 }418 }
419419
420 fn errorable3() !i32 {420 fn errorable3() !i32 {
421 var x: Foo = (try getFoo3()) orelse return error.Other;421 const x: Foo = (try getFoo3()) orelse return error.Other;
422 return x.a;422 return x.a;
423 }423 }
424424
...@@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" {...@@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" {
673 const a: error{B}!void = {};673 const a: error{B}!void = {};
674 const b: error{A}!void = {};674 const b: error{A}!void = {};
675 var cond = true;675 var cond = true;
676 _ = &cond;
676 const err = if (cond) a else b;677 const err = if (cond) a else b;
677 try err;678 try err;
678}679}
...@@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" {...@@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" {
681 const S = struct {682 const S = struct {
682 fn foo() !void {683 fn foo() !void {
683 var a = false;684 var a = false;
685 _ = &a;
684 if (a) {686 if (a) {
685 const b: error{A}!void = error.A;687 const b: error{A}!void = error.A;
686 return b;688 return b;
...@@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" {...@@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" {
831833
832 fn foo() anyerror!I {834 fn foo() anyerror!I {
833 var i: I = .{ .x = 1234 };835 var i: I = .{ .x = 1234 };
836 _ = &i;
834 return i;837 return i;
835 }838 }
836 };839 };
...@@ -842,6 +845,7 @@ test "compare error union and error set" {...@@ -842,6 +845,7 @@ test "compare error union and error set" {
842845
843 var a: anyerror = error.Foo;846 var a: anyerror = error.Foo;
844 var b: anyerror!u32 = error.Bar;847 var b: anyerror!u32 = error.Bar;
848 _ = &a;
845849
846 try expect(a != b);850 try expect(a != b);
847 try expect(b != a);851 try expect(b != a);
...@@ -863,6 +867,7 @@ fn non_errorable() void {...@@ -863,6 +867,7 @@ fn non_errorable() void {
863 // This test is needed because stage 2's fix for #1923 means that catch blocks interact867 // This test is needed because stage 2's fix for #1923 means that catch blocks interact
864 // with the error return trace index.868 // with the error return trace index.
865 var x: error{Foo}!void = {};869 var x: error{Foo}!void = {};
870 _ = &x;
866 return x catch {};871 return x catch {};
867}872}
868873
...@@ -902,6 +907,7 @@ test "optional error union return type" {...@@ -902,6 +907,7 @@ test "optional error union return type" {
902 const S = struct {907 const S = struct {
903 fn foo() ?anyerror!u32 {908 fn foo() ?anyerror!u32 {
904 var x: u32 = 1234;909 var x: u32 = 1234;
910 _ = &x;
905 return @as(anyerror!u32, x);911 return @as(anyerror!u32, x);
906 }912 }
907 };913 };
test/behavior/eval.zig+39-20
...@@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 {...@@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 {
37 const x: i32 = 1;37 const x: i32 = 1;
38 const y: i32 = 2;38 const y: i32 = 2;
39 comptime var z: i32 = if (a) x else y;39 comptime var z: i32 = if (a) x else y;
40 _ = &z;
40 return z;41 return z;
41}42}
42test "inline variable gets result of const if" {43test "inline variable gets result of const if" {
...@@ -74,6 +75,7 @@ test "constant expressions" {...@@ -74,6 +75,7 @@ test "constant expressions" {
74 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO75 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7576
76 var array: [array_size]u8 = undefined;77 var array: [array_size]u8 = undefined;
78 _ = &array;
77 try expect(@sizeOf(@TypeOf(array)) == 20);79 try expect(@sizeOf(@TypeOf(array)) == 20);
78}80}
79const array_size: u8 = 20;81const array_size: u8 = 20;
...@@ -129,7 +131,7 @@ test "pointer to type" {...@@ -129,7 +131,7 @@ test "pointer to type" {
129 comptime {131 comptime {
130 var T: type = i32;132 var T: type = i32;
131 try expect(T == i32);133 try expect(T == i32);
132 var ptr = &T;134 const ptr = &T;
133 try expect(@TypeOf(ptr) == *type);135 try expect(@TypeOf(ptr) == *type);
134 ptr.* = f32;136 ptr.* = f32;
135 try expect(T == f32);137 try expect(T == f32);
...@@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void {...@@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void {
372test "zero extend from u0 to u1" {374test "zero extend from u0 to u1" {
373 var zero_u0: u0 = 0;375 var zero_u0: u0 = 0;
374 var zero_u1: u1 = zero_u0;376 var zero_u1: u1 = zero_u0;
377 _ = .{ &zero_u0, &zero_u1 };
375 try expect(zero_u1 == 0);378 try expect(zero_u1 == 0);
376}379}
377380
...@@ -408,6 +411,7 @@ test "inline for with same type but different values" {...@@ -408,6 +411,7 @@ test "inline for with same type but different values" {
408 var res: usize = 0;411 var res: usize = 0;
409 inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {412 inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {
410 var a: T = undefined;413 var a: T = undefined;
414 _ = &a;
411 res += a.len;415 res += a.len;
412 }416 }
413 try expect(res == 5);417 try expect(res == 5);
...@@ -460,9 +464,9 @@ test "comptime shl" {...@@ -460,9 +464,9 @@ test "comptime shl" {
460 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO464 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
461 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;465 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
462466
463 var a: u128 = 3;467 const a: u128 = 3;
464 var b: u7 = 63;468 const b: u7 = 63;
465 var c: u128 = 3 << 63;469 const c: u128 = 3 << 63;
466 try expect((a << b) == c);470 try expect((a << b) == c);
467}471}
468472
...@@ -489,6 +493,7 @@ test "comptime shlWithOverflow" {...@@ -489,6 +493,7 @@ test "comptime shlWithOverflow" {
489493
490 const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0];494 const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0];
491 var a = ~@as(u64, 0);495 var a = ~@as(u64, 0);
496 _ = &a;
492 const rt_shifted = @shlWithOverflow(a, 16)[0];497 const rt_shifted = @shlWithOverflow(a, 16)[0];
493498
494 try expect(ct_shifted == rt_shifted);499 try expect(ct_shifted == rt_shifted);
...@@ -521,7 +526,8 @@ test "runtime 128 bit integer division" {...@@ -521,7 +526,8 @@ test "runtime 128 bit integer division" {
521526
522 var a: u128 = 152313999999999991610955792383;527 var a: u128 = 152313999999999991610955792383;
523 var b: u128 = 10000000000000000000;528 var b: u128 = 10000000000000000000;
524 var c = a / b;529 _ = .{ &a, &b };
530 const c = a / b;
525 try expect(c == 15231399999);531 try expect(c == 15231399999);
526}532}
527533
...@@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio...@@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
555 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO561 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
556562
557 var runtime = [1]i32{3};563 var runtime = [1]i32{3};
564 _ = &runtime;
558 comptime var i: usize = 0;565 comptime var i: usize = 0;
559 inline while (i < 2) : (i += 1) {566 inline while (i < 2) : (i += 1) {
560 const result = if (i == 0) [1]i32{2} else runtime;567 const result = if (i == 0) [1]i32{2} else runtime;
...@@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" {...@@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
692 };699 };
693700
694 const s = S{ .a = 2 };701 const s = S{ .a = 2 };
695 var b = s.b();702 const b = s.b();
696 try expect(b == 2);703 try expect(b == 2);
697}704}
698705
...@@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" {...@@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" {
759766
760 var a = [2]u3{ 1, 7 };767 var a = [2]u3{ 1, 7 };
761 var b = [3]u8{ 200, 225, 255 };768 var b = [3]u8{ 200, 225, 255 };
762 var c = a ++ b;769 _ = .{ &a, &b };
770 const c = a ++ b;
763 comptime assert(@TypeOf(c) == [5]u8);771 comptime assert(@TypeOf(c) == [5]u8);
764 try expect(c[0] == 1);772 try expect(c[0] == 1);
765 try expect(c[1] == 7);773 try expect(c[1] == 7);
...@@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" {...@@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" {
775783
776 var a = [2]u3{ 1, 7 };784 var a = [2]u3{ 1, 7 };
777 var b = [3]u8{ 200, 225, 255 };785 var b = [3]u8{ 200, 225, 255 };
778 var c = &a ++ &b;786 const c = &a ++ &b;
779 comptime assert(@TypeOf(c) == *[5]u8);787 comptime assert(@TypeOf(c) == *[5]u8);
780 try expect(c[0] == 1);788 try expect(c[0] == 1);
781 try expect(c[1] == 7);789 try expect(c[1] == 7);
...@@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" {...@@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" {
791799
792 var a = [2]u3{ 1, 7 };800 var a = [2]u3{ 1, 7 };
793 var b = [3:69]u8{ 200, 225, 255 };801 var b = [3:69]u8{ 200, 225, 255 };
794 var c = a ++ b;802 _ = .{ &a, &b };
803 const c = a ++ b;
795 comptime assert(@TypeOf(c) == [5:69]u8);804 comptime assert(@TypeOf(c) == [5:69]u8);
796 try expect(c[0] == 1);805 try expect(c[0] == 1);
797 try expect(c[1] == 7);806 try expect(c[1] == 7);
798 try expect(c[2] == 200);807 try expect(c[2] == 200);
799 try expect(c[3] == 225);808 try expect(c[3] == 225);
800 try expect(c[4] == 255);809 try expect(c[4] == 255);
801 var ptr: [*]const u8 = &c;810 const ptr: [*]const u8 = &c;
802 try expect(ptr[5] == 69);811 try expect(ptr[5] == 69);
803}812}
804813
...@@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" {...@@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" {
808817
809 var a = [2]u3{ 1, 7 };818 var a = [2]u3{ 1, 7 };
810 var b = [3:69]u8{ 200, 225, 255 };819 var b = [3:69]u8{ 200, 225, 255 };
811 var c = &a ++ &b;820 const c = &a ++ &b;
812 comptime assert(@TypeOf(c) == *[5:69]u8);821 comptime assert(@TypeOf(c) == *[5:69]u8);
813 try expect(c[0] == 1);822 try expect(c[0] == 1);
814 try expect(c[1] == 7);823 try expect(c[1] == 7);
815 try expect(c[2] == 200);824 try expect(c[2] == 200);
816 try expect(c[3] == 225);825 try expect(c[3] == 225);
817 try expect(c[4] == 255);826 try expect(c[4] == 255);
818 var ptr: [*]const u8 = c;827 const ptr: [*]const u8 = c;
819 try expect(ptr[5] == 69);828 try expect(ptr[5] == 69);
820}829}
821830
...@@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" {...@@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" {
825 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO834 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
826835
827 var a = [2:7]u3{ 1, 6 };836 var a = [2:7]u3{ 1, 6 };
828 var b = a ** 2;837 _ = &a;
838 const b = a ** 2;
829 comptime assert(@TypeOf(b) == [4:7]u3);839 comptime assert(@TypeOf(b) == [4:7]u3);
830 try expect(b[0] == 1);840 try expect(b[0] == 1);
831 try expect(b[1] == 6);841 try expect(b[1] == 6);
832 try expect(b[2] == 1);842 try expect(b[2] == 1);
833 try expect(b[3] == 6);843 try expect(b[3] == 6);
834 var ptr: [*]const u3 = &b;844 const ptr: [*]const u3 = &b;
835 try expect(ptr[4] == 7);845 try expect(ptr[4] == 7);
836}846}
837847
...@@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" {...@@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" {
841 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO851 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
842852
843 var a = [2:7]u3{ 1, 6 };853 var a = [2:7]u3{ 1, 6 };
844 var b = &a ** 2;854 const b = &a ** 2;
845 comptime assert(@TypeOf(b) == *[4:7]u3);855 comptime assert(@TypeOf(b) == *[4:7]u3);
846 try expect(b[0] == 1);856 try expect(b[0] == 1);
847 try expect(b[1] == 6);857 try expect(b[1] == 6);
848 try expect(b[2] == 1);858 try expect(b[2] == 1);
849 try expect(b[3] == 6);859 try expect(b[3] == 6);
850 var ptr: [*]const u3 = b;860 const ptr: [*]const u3 = b;
851 try expect(ptr[4] == 7);861 try expect(ptr[4] == 7);
852}862}
853863
...@@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" {...@@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" {
913 .x = i,923 .x = i,
914 };924 };
915 }925 }
916 var ptr = @as([*]S, @ptrCast(&array));926 var ptr: [*]S = @ptrCast(&array);
917 var x = ptr[0].x;927 const x = ptr[0].x;
918 assert(x == 0);928 assert(x == 0);
919 ptr += 1;929 ptr += 1;
920 assert(ptr[1].x == 2);930 assert(ptr[1].x == 2);
...@@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" {...@@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" {
953 const S = struct {963 const S = struct {
954 fn b(c: anytype) !void {964 fn b(c: anytype) !void {
955 const D = struct { c: @TypeOf(c) };965 const D = struct { c: @TypeOf(c) };
956 var d = D{ .c = c };966 const d: D = .{ .c = c };
957 try expect(d.c == 1234);967 try expect(d.c == 1234);
958 }968 }
959 };969 };
960 var c: i32 = 1234;970 var c: i32 = 1234;
971 _ = &c;
961 try S.b(c);972 try S.b(c);
962}973}
963974
...@@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" {...@@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" {
966 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO977 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
967978
968 var x: u32 = 1234;979 var x: u32 = 1234;
980 _ = &x;
969 const S = struct { val: @TypeOf(x + 100) };981 const S = struct { val: @TypeOf(x + 100) };
970 const s: S = .{ .val = x };982 const s: S = .{ .val = x };
971 try expect(s.val == 1234);983 try expect(s.val == 1234);
...@@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea...@@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea
977 const S = struct {989 const S = struct {
978 fn doTheTest() !void {990 fn doTheTest() !void {
979 var runtime: u8 = 'b';991 var runtime: u8 = 'b';
992 _ = &runtime;
980 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {993 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {
981 bar();994 bar();
982 if (byte == runtime) {995 if (byte == runtime) {
...@@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t...@@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t
1010 const S = struct {1023 const S = struct {
1011 fn doTheTest() !void {1024 fn doTheTest() !void {
1012 var runtime: u8 = 'b';1025 var runtime: u8 = 'b';
1026 _ = &runtime;
1013 outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| {1027 outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| {
1014 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {1028 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {
1015 bar(outer_byte);1029 bar(outer_byte);
...@@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" {...@@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" {
13871401
1388test "inline for inside a runtime condition" {1402test "inline for inside a runtime condition" {
1389 var a = false;1403 var a = false;
1404 _ = &a;
1390 if (a) {1405 if (a) {
1391 const arr = .{ 1, 2, 3 };1406 const arr = .{ 1, 2, 3 };
1392 inline for (arr) |val| {1407 inline for (arr) |val| {
...@@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" {...@@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" {
15221537
1523 const array = [1]u8{'A'} ++ [1]?u8{null};1538 const array = [1]u8{'A'} ++ [1]?u8{null};
1524 var index: usize = 0;1539 var index: usize = 0;
1540 _ = &index;
1525 try expect(array[index].? == 'A');1541 try expect(array[index].? == 'A');
1526}1542}
15271543
...@@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" {...@@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" {
1556 var v: @This() = c;1572 var v: @This() = c;
1557 };1573 };
1558 var p = &S.c;1574 var p = &S.c;
1575 _ = &p;
1559 try std.testing.expect(p.x == S.c.x);1576 try std.testing.expect(p.x == S.c.x);
1560 S.v.x = 2;1577 S.v.x = 2;
1561 try std.testing.expect(p.x == S.c.x);1578 try std.testing.expect(p.x == S.c.x);
...@@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" {...@@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" {
1625test "if inside a switch" {1642test "if inside a switch" {
1626 var condition = true;1643 var condition = true;
1627 var wave_type: u32 = 0;1644 var wave_type: u32 = 0;
1628 var sample: i32 = switch (wave_type) {1645 _ = .{ &condition, &wave_type };
1646 const sample: i32 = switch (wave_type) {
1629 0 => if (condition) 2 else 3,1647 0 => if (condition) 2 else 3,
1630 1 => 100,1648 1 => 100,
1631 2 => 200,1649 2 => 200,
...@@ -1673,6 +1691,7 @@ test "@inComptime" {...@@ -1673,6 +1691,7 @@ test "@inComptime" {
1673comptime {1691comptime {
1674 var foo = [3]u8{ 0x55, 0x55, 0x55 };1692 var foo = [3]u8{ 0x55, 0x55, 0x55 };
1675 var bar = [2]u8{ 1, 2 };1693 var bar = [2]u8{ 1, 2 };
1694 _ = .{ &foo, &bar };
1676 foo[0..2].* = bar;1695 foo[0..2].* = bar;
1677 assert(foo[0] == 1);1696 assert(foo[0] == 1);
1678 assert(foo[1] == 2);1697 assert(foo[1] == 2);
test/behavior/extern_struct_zero_size_fields.zig+1-1
...@@ -17,5 +17,5 @@ const T = extern struct {...@@ -17,5 +17,5 @@ const T = extern struct {
1717
18test {18test {
19 var t: T = .{};19 var t: T = .{};
20 _ = t;20 _ = &t;
21}21}
test/behavior/floatop.zig+150-14
...@@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" {...@@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" {
42fn testAdd(comptime T: type) !void {42fn testAdd(comptime T: type) !void {
43 var one_point_two_five: T = 1.25;43 var one_point_two_five: T = 1.25;
44 var two_point_seven_five: T = 2.75;44 var two_point_seven_five: T = 2.75;
45 _ = &one_point_two_five;
46 _ = &two_point_seven_five;
45 try expect(one_point_two_five + two_point_seven_five == 4);47 try expect(one_point_two_five + two_point_seven_five == 4);
46}48}
4749
...@@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" {...@@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" {
74fn testSub(comptime T: type) !void {76fn testSub(comptime T: type) !void {
75 var one_point_two_five: T = 1.25;77 var one_point_two_five: T = 1.25;
76 var two_point_seven_five: T = 2.75;78 var two_point_seven_five: T = 2.75;
79 _ = &one_point_two_five;
80 _ = &two_point_seven_five;
77 try expect(one_point_two_five - two_point_seven_five == -1.5);81 try expect(one_point_two_five - two_point_seven_five == -1.5);
78}82}
7983
...@@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" {...@@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" {
106fn testMul(comptime T: type) !void {110fn testMul(comptime T: type) !void {
107 var one_point_two_five: T = 1.25;111 var one_point_two_five: T = 1.25;
108 var two_point_seven_five: T = 2.75;112 var two_point_seven_five: T = 2.75;
113 _ = &one_point_two_five;
114 _ = &two_point_seven_five;
109 try expect(one_point_two_five * two_point_seven_five == 3.4375);115 try expect(one_point_two_five * two_point_seven_five == 3.4375);
110}116}
111117
...@@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void {...@@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void {
152 {158 {
153 // No decimal part159 // No decimal part
154 var x: T = 1.0;160 var x: T = 1.0;
161 _ = &x;
155 try expect(x == 1.0);162 try expect(x == 1.0);
156 try expect(x != 0.0);163 try expect(x != 0.0);
157 try expect(x > 0.0);164 try expect(x > 0.0);
...@@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void {...@@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void {
162 {169 {
163 // Non-zero decimal part170 // Non-zero decimal part
164 var x: T = 1.5;171 var x: T = 1.5;
172 _ = &x;
165 try expect(x != 1.0);173 try expect(x != 1.0);
166 try expect(x != 2.0);174 try expect(x != 2.0);
167 try expect(x > 1.0);175 try expect(x > 1.0);
...@@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void {...@@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void {
184 math.floatMax(T),192 math.floatMax(T),
185 math.inf(T),193 math.inf(T),
186 };194 };
195 _ = &edges;
187 for (edges, 0..) |rhs, rhs_i| {196 for (edges, 0..) |rhs, rhs_i| {
188 for (edges, 0..) |lhs, lhs_i| {197 for (edges, 0..) |lhs, lhs_i| {
189 const no_nan = lhs_i != 5 and rhs_i != 5;198 const no_nan = lhs_i != 5 and rhs_i != 5;
...@@ -212,6 +221,7 @@ test "different sized float comparisons" {...@@ -212,6 +221,7 @@ test "different sized float comparisons" {
212fn testDifferentSizedFloatComparisons() !void {221fn testDifferentSizedFloatComparisons() !void {
213 var a: f16 = 1;222 var a: f16 = 1;
214 var b: f64 = 2;223 var b: f64 = 2;
224 _ = .{ &a, &b };
215 try expect(a < b);225 try expect(a < b);
216}226}
217227
...@@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" {...@@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" {
240 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;250 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
241251
242 const a: f128 = -2;252 const a: f128 = -2;
243 var b = @as(i64, @intFromFloat(a));253 var b: i64 = @intFromFloat(a);
254 _ = &b;
244 try expect(@as(i64, -2) == b);255 try expect(@as(i64, -2) == b);
245}256}
246257
...@@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void {...@@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void {
331 try expect(math.isNan(@sqrt(neg_one)));342 try expect(math.isNan(@sqrt(neg_one)));
332 var nan: T = math.nan(T);343 var nan: T = math.nan(T);
333 try expect(math.isNan(@sqrt(nan)));344 try expect(math.isNan(@sqrt(nan)));
345
346 _ = .{
347 &four,
348 &nine,
349 &twenty_five,
350 &sixty_four,
351 &one_point_one,
352 &two,
353 &three_point_six,
354 &sixty_four_point_one,
355 &twelve,
356 &thirteen,
357 &fourteen,
358 &a,
359 &b,
360 &c,
361 &inf,
362 &zero,
363 &neg_zero,
364 &neg_one,
365 &nan,
366 };
334}367}
335368
336test "@sqrt with vectors" {369test "@sqrt with vectors" {
...@@ -345,7 +378,8 @@ test "@sqrt with vectors" {...@@ -345,7 +378,8 @@ test "@sqrt with vectors" {
345378
346fn testSqrtWithVectors() !void {379fn testSqrtWithVectors() !void {
347 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };380 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
348 var result = @sqrt(v);381 _ = &v;
382 const result = @sqrt(v);
349 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));383 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
350 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));384 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
351 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));385 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
...@@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" {...@@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" {
394fn testSin(comptime T: type) !void {428fn testSin(comptime T: type) !void {
395 const eps = epsForType(T);429 const eps = epsForType(T);
396 var zero: T = 0;430 var zero: T = 0;
431 _ = &zero;
397 try expect(@sin(zero) == 0);432 try expect(@sin(zero) == 0);
398 var pi: T = math.pi;433 var pi: T = math.pi;
434 _ = &pi;
399 try expect(math.approxEqAbs(T, @sin(pi), 0, eps));435 try expect(math.approxEqAbs(T, @sin(pi), 0, eps));
400 try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps));436 try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps));
401 try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps));437 try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps));
...@@ -414,7 +450,8 @@ test "@sin with vectors" {...@@ -414,7 +450,8 @@ test "@sin with vectors" {
414450
415fn testSinWithVectors() !void {451fn testSinWithVectors() !void {
416 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };452 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
417 var result = @sin(v);453 _ = &v;
454 const result = @sin(v);
418 try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));455 try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
419 try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));456 try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
420 try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));457 try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
...@@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" {...@@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" {
463fn testCos(comptime T: type) !void {500fn testCos(comptime T: type) !void {
464 const eps = epsForType(T);501 const eps = epsForType(T);
465 var zero: T = 0;502 var zero: T = 0;
503 _ = &zero;
466 try expect(@cos(zero) == 1);504 try expect(@cos(zero) == 1);
467 var pi: T = math.pi;505 var pi: T = math.pi;
506 _ = &pi;
468 try expect(math.approxEqAbs(T, @cos(pi), -1, eps));507 try expect(math.approxEqAbs(T, @cos(pi), -1, eps));
469 try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps));508 try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps));
470 try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps));509 try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps));
...@@ -483,7 +522,8 @@ test "@cos with vectors" {...@@ -483,7 +522,8 @@ test "@cos with vectors" {
483522
484fn testCosWithVectors() !void {523fn testCosWithVectors() !void {
485 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };524 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
486 var result = @cos(v);525 _ = &v;
526 const result = @cos(v);
487 try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));527 try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
488 try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));528 try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
489 try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));529 try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
...@@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" {...@@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" {
532fn testTan(comptime T: type) !void {572fn testTan(comptime T: type) !void {
533 const eps = epsForType(T);573 const eps = epsForType(T);
534 var zero: T = 0;574 var zero: T = 0;
575 _ = &zero;
535 try expect(@tan(zero) == 0);576 try expect(@tan(zero) == 0);
536 var pi: T = math.pi;577 var pi: T = math.pi;
578 _ = &pi;
537 try expect(math.approxEqAbs(T, @tan(pi), 0, eps));579 try expect(math.approxEqAbs(T, @tan(pi), 0, eps));
538 try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps));580 try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps));
539 try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps));581 try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps));
...@@ -552,7 +594,8 @@ test "@tan with vectors" {...@@ -552,7 +594,8 @@ test "@tan with vectors" {
552594
553fn testTanWithVectors() !void {595fn testTanWithVectors() !void {
554 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };596 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
555 var result = @tan(v);597 _ = &v;
598 const result = @tan(v);
556 try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon));599 try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon));
557 try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon));600 try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon));
558 try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon));601 try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon));
...@@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" {...@@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" {
600643
601fn testExp(comptime T: type) !void {644fn testExp(comptime T: type) !void {
602 const eps = epsForType(T);645 const eps = epsForType(T);
646
603 var zero: T = 0;647 var zero: T = 0;
648 _ = &zero;
604 try expect(@exp(zero) == 1);649 try expect(@exp(zero) == 1);
650
605 var two: T = 2;651 var two: T = 2;
652 _ = &two;
606 try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps));653 try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps));
654
607 var five: T = 5;655 var five: T = 5;
656 _ = &five;
608 try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps));657 try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps));
609}658}
610659
...@@ -621,7 +670,8 @@ test "@exp with vectors" {...@@ -621,7 +670,8 @@ test "@exp with vectors" {
621670
622fn testExpWithVectors() !void {671fn testExpWithVectors() !void {
623 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };672 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
624 var result = @exp(v);673 _ = &v;
674 const result = @exp(v);
625 try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));675 try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
626 try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));676 try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
627 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));677 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
...@@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void {...@@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void {
675 try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps));725 try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps));
676 var four_point_five: T = 4.5;726 var four_point_five: T = 4.5;
677 try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps));727 try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps));
728 _ = .{ &two, &one_point_five, &four_point_five };
678}729}
679730
680test "@exp2 with @vectors" {731test "@exp2 with @vectors" {
...@@ -690,7 +741,8 @@ test "@exp2 with @vectors" {...@@ -690,7 +741,8 @@ test "@exp2 with @vectors" {
690741
691fn testExp2WithVectors() !void {742fn testExp2WithVectors() !void {
692 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };743 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
693 var result = @exp2(v);744 _ = &v;
745 const result = @exp2(v);
694 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));746 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
695 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));747 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
696 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));748 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
...@@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void {...@@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void {
744 try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps));796 try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps));
745 var five: T = 5;797 var five: T = 5;
746 try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps));798 try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps));
799 _ = .{ &e, &two, &five };
747}800}
748801
749test "@log with @vectors" {802test "@log with @vectors" {
...@@ -756,7 +809,8 @@ test "@log with @vectors" {...@@ -756,7 +809,8 @@ test "@log with @vectors" {
756809
757 {810 {
758 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };811 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
759 var result = @log(v);812 _ = &v;
813 const result = @log(v);
760 try expect(@log(@as(f32, 1.1)) == result[0]);814 try expect(@log(@as(f32, 1.1)) == result[0]);
761 try expect(@log(@as(f32, 2.2)) == result[1]);815 try expect(@log(@as(f32, 2.2)) == result[1]);
762 try expect(@log(@as(f32, 0.3)) == result[2]);816 try expect(@log(@as(f32, 0.3)) == result[2]);
...@@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void {...@@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void {
811 try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps));865 try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps));
812 var ten: T = 10;866 var ten: T = 10;
813 try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps));867 try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps));
868 _ = .{ &four, &six, &ten };
814}869}
815870
816test "@log2 with vectors" {871test "@log2 with vectors" {
...@@ -830,7 +885,8 @@ test "@log2 with vectors" {...@@ -830,7 +885,8 @@ test "@log2 with vectors" {
830885
831fn testLog2WithVectors() !void {886fn testLog2WithVectors() !void {
832 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };887 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
833 var result = @log2(v);888 _ = &v;
889 const result = @log2(v);
834 try expect(@log2(@as(f32, 1.1)) == result[0]);890 try expect(@log2(@as(f32, 1.1)) == result[0]);
835 try expect(@log2(@as(f32, 2.2)) == result[1]);891 try expect(@log2(@as(f32, 2.2)) == result[1]);
836 try expect(@log2(@as(f32, 0.3)) == result[2]);892 try expect(@log2(@as(f32, 0.3)) == result[2]);
...@@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void {...@@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void {
884 try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps));940 try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps));
885 var fifty: T = 50;941 var fifty: T = 50;
886 try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps));942 try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps));
943 _ = .{ &hundred, &fifteen, &fifty };
887}944}
888945
889test "@log10 with vectors" {946test "@log10 with vectors" {
...@@ -899,7 +956,8 @@ test "@log10 with vectors" {...@@ -899,7 +956,8 @@ test "@log10 with vectors" {
899956
900fn testLog10WithVectors() !void {957fn testLog10WithVectors() !void {
901 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };958 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
902 var result = @log10(v);959 _ = &v;
960 const result = @log10(v);
903 try expect(@log10(@as(f32, 1.1)) == result[0]);961 try expect(@log10(@as(f32, 1.1)) == result[0]);
904 try expect(@log10(@as(f32, 2.2)) == result[1]);962 try expect(@log10(@as(f32, 2.2)) == result[1]);
905 try expect(@log10(@as(f32, 0.3)) == result[2]);963 try expect(@log10(@as(f32, 0.3)) == result[2]);
...@@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void {...@@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void {
987 try expect(math.isPositiveInf(@abs(neg_inf)));1045 try expect(math.isPositiveInf(@abs(neg_inf)));
988 var nan: T = math.nan(T);1046 var nan: T = math.nan(T);
989 try expect(math.isNan(@abs(nan)));1047 try expect(math.isNan(@abs(nan)));
1048
1049 _ = .{
1050 &two_point_five,
1051 &neg_two_point_five,
1052 &twelve,
1053 &neg_fourteen,
1054 &one,
1055 &neg_one,
1056 &min,
1057 &neg_min,
1058 &max,
1059 &neg_max,
1060 &zero,
1061 &neg_zero,
1062 &true_min,
1063 &neg_true_min,
1064 &inf,
1065 &neg_inf,
1066 &nan,
1067 };
990}1068}
9911069
992test "@abs with vectors" {1070test "@abs with vectors" {
...@@ -1001,7 +1079,8 @@ test "@abs with vectors" {...@@ -1001,7 +1079,8 @@ test "@abs with vectors" {
10011079
1002fn testFabsWithVectors() !void {1080fn testFabsWithVectors() !void {
1003 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };1081 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1004 var result = @abs(v);1082 _ = &v;
1083 const result = @abs(v);
1005 try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon));1084 try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon));
1006 try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon));1085 try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon));
1007 try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon));1086 try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon));
...@@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void {...@@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void {
1070 try expect(@floor(fourteen_point_seven) == 14.0);1149 try expect(@floor(fourteen_point_seven) == 14.0);
1071 var neg_fourteen_point_seven: T = -14.7;1150 var neg_fourteen_point_seven: T = -14.7;
1072 try expect(@floor(neg_fourteen_point_seven) == -15.0);1151 try expect(@floor(neg_fourteen_point_seven) == -15.0);
1152
1153 _ = .{
1154 &two_point_one,
1155 &neg_two_point_one,
1156 &three_point_five,
1157 &neg_three_point_five,
1158 &twelve,
1159 &neg_twelve,
1160 &fourteen_point_seven,
1161 &neg_fourteen_point_seven,
1162 };
1073}1163}
10741164
1075test "@floor with vectors" {1165test "@floor with vectors" {
...@@ -1086,7 +1176,8 @@ test "@floor with vectors" {...@@ -1086,7 +1176,8 @@ test "@floor with vectors" {
10861176
1087fn testFloorWithVectors() !void {1177fn testFloorWithVectors() !void {
1088 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };1178 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1089 var result = @floor(v);1179 _ = &v;
1180 const result = @floor(v);
1090 try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));1181 try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
1091 try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));1182 try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
1092 try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));1183 try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
...@@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void {...@@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void {
1155 try expect(@ceil(fourteen_point_seven) == 15.0);1246 try expect(@ceil(fourteen_point_seven) == 15.0);
1156 var neg_fourteen_point_seven: T = -14.7;1247 var neg_fourteen_point_seven: T = -14.7;
1157 try expect(@ceil(neg_fourteen_point_seven) == -14.0);1248 try expect(@ceil(neg_fourteen_point_seven) == -14.0);
1249
1250 _ = .{
1251 &two_point_one,
1252 &neg_two_point_one,
1253 &three_point_five,
1254 &neg_three_point_five,
1255 &twelve,
1256 &neg_twelve,
1257 &fourteen_point_seven,
1258 &neg_fourteen_point_seven,
1259 };
1158}1260}
11591261
1160test "@ceil with vectors" {1262test "@ceil with vectors" {
...@@ -1171,7 +1273,8 @@ test "@ceil with vectors" {...@@ -1171,7 +1273,8 @@ test "@ceil with vectors" {
11711273
1172fn testCeilWithVectors() !void {1274fn testCeilWithVectors() !void {
1173 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };1275 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1174 var result = @ceil(v);1276 _ = &v;
1277 const result = @ceil(v);
1175 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));1278 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
1176 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));1279 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
1177 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));1280 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
...@@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void {...@@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void {
1250 try expect(@trunc(fourteen_point_seven) == 14.0);1353 try expect(@trunc(fourteen_point_seven) == 14.0);
1251 var neg_fourteen_point_seven: T = -14.7;1354 var neg_fourteen_point_seven: T = -14.7;
1252 try expect(@trunc(neg_fourteen_point_seven) == -14.0);1355 try expect(@trunc(neg_fourteen_point_seven) == -14.0);
1356
1357 _ = .{
1358 &two_point_one,
1359 &neg_two_point_one,
1360 &three_point_five,
1361 &neg_three_point_five,
1362 &twelve,
1363 &neg_twelve,
1364 &fourteen_point_seven,
1365 &neg_fourteen_point_seven,
1366 };
1253}1367}
12541368
1255test "@trunc with vectors" {1369test "@trunc with vectors" {
...@@ -1266,7 +1380,8 @@ test "@trunc with vectors" {...@@ -1266,7 +1380,8 @@ test "@trunc with vectors" {
12661380
1267fn testTruncWithVectors() !void {1381fn testTruncWithVectors() !void {
1268 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };1382 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1269 var result = @trunc(v);1383 _ = &v;
1384 const result = @trunc(v);
1270 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));1385 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
1271 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));1386 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
1272 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));1387 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
...@@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void {...@@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void {
1365 var neg_nan: T = -math.nan(T);1480 var neg_nan: T = -math.nan(T);
1366 try expect(math.isNan(-neg_nan));1481 try expect(math.isNan(-neg_nan));
1367 try expect(!math.signbit(-neg_nan));1482 try expect(!math.signbit(-neg_nan));
1483
1484 _ = .{
1485 &two_point_five,
1486 &neg_two_point_five,
1487 &twelve,
1488 &neg_fourteen,
1489 &one,
1490 &neg_one,
1491 &min,
1492 &neg_min,
1493 &max,
1494 &neg_max,
1495 &zero,
1496 &neg_zero,
1497 &true_min,
1498 &neg_true_min,
1499 &inf,
1500 &neg_inf,
1501 &nan,
1502 &neg_nan,
1503 };
1368}1504}
13691505
1370test "eval @setFloatMode at compile-time" {1506test "eval @setFloatMode at compile-time" {
test/behavior/fn.zig+9-4
...@@ -21,6 +21,7 @@ fn testLocVars(b: i32) void {...@@ -21,6 +21,7 @@ fn testLocVars(b: i32) void {
2121
22test "mutable local variables" {22test "mutable local variables" {
23 var zero: i32 = 0;23 var zero: i32 = 0;
24 _ = &zero;
24 try expect(zero == 0);25 try expect(zero == 0);
2526
26 var i = @as(i32, 0);27 var i = @as(i32, 0);
...@@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 {...@@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 {
70test "return inner function which references comptime variable of outer function" {71test "return inner function which references comptime variable of outer function" {
71 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;72 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7273
73 var func = outer(10);74 const func = outer(10);
74 try expect(func(3) == 7);75 try expect(func(3) == 7);
75}76}
7677
...@@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" {...@@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" {
259260
260 const S = struct {261 const S = struct {
261 fn entry() !void {262 fn entry() !void {
262 var x = Foo{263 const x = Foo{
263 .field = optionalPtr(),264 .field = optionalPtr(),
264 };265 };
265 try expect(x.field.?.* == 999);266 try expect(x.field.?.* == 999);
...@@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" {...@@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" {
386 const S = struct {387 const S = struct {
387 fn doTheTest() !void {388 fn doTheTest() !void {
388 var x: i32 = 1;389 var x: i32 = 1;
390 _ = &x;
389 try expect(foo(x) == 10);391 try expect(foo(x) == 10);
390 try expect(foo(i32) == 20);392 try expect(foo(i32) == 20);
391 }393 }
...@@ -413,11 +415,11 @@ test "import passed byref to function in return type" {...@@ -413,11 +415,11 @@ test "import passed byref to function in return type" {
413415
414 const S = struct {416 const S = struct {
415 fn get() @import("std").ArrayListUnmanaged(i32) {417 fn get() @import("std").ArrayListUnmanaged(i32) {
416 var x: @import("std").ArrayListUnmanaged(i32) = .{};418 const x: @import("std").ArrayListUnmanaged(i32) = .{};
417 return x;419 return x;
418 }420 }
419 };421 };
420 var list = S.get();422 const list = S.get();
421 try expect(list.items.len == 0);423 try expect(list.items.len == 0);
422}424}
423425
...@@ -434,11 +436,13 @@ test "implicit cast function to function ptr" {...@@ -434,11 +436,13 @@ test "implicit cast function to function ptr" {
434 }436 }
435 };437 };
436 var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue;438 var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue;
439 _ = &fnPtr1;
437 try expect(fnPtr1() == 123);440 try expect(fnPtr1() == 123);
438 const S2 = struct {441 const S2 = struct {
439 extern fn someFunctionThatReturnsAValue() c_int;442 extern fn someFunctionThatReturnsAValue() c_int;
440 };443 };
441 var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue;444 var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue;
445 _ = &fnPtr2;
442 try expect(fnPtr2() == 123);446 try expect(fnPtr2() == 123);
443}447}
444448
...@@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" {...@@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" {
588 const bar = foo;592 const bar = foo;
589 };593 };
590 var a = &S.bar;594 var a = &S.bar;
595 _ = &a;
591 try std.testing.expect(S.foo() == a());596 try std.testing.expect(S.foo() == a());
592}597}
test/behavior/fn_in_struct_in_comptime.zig+1-2
...@@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize {...@@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize {
5 comptime {5 comptime {
6 return struct {6 return struct {
7 fn func(ptr: *u8) usize {7 fn func(ptr: *u8) usize {
8 var u = @intFromPtr(ptr);8 return @intFromPtr(ptr);
9 return u;
10 }9 }
11 }.func;10 }.func;
12 }11 }
test/behavior/for.zig+13-6
...@@ -26,7 +26,7 @@ test "break from outer for loop" {...@@ -26,7 +26,7 @@ test "break from outer for loop" {
26}26}
2727
28fn testBreakOuter() !void {28fn testBreakOuter() !void {
29 var array = "aoeu";29 const array = "aoeu";
30 var count: usize = 0;30 var count: usize = 0;
31 outer: for (array) |_| {31 outer: for (array) |_| {
32 for (array) |_| {32 for (array) |_| {
...@@ -43,7 +43,7 @@ test "continue outer for loop" {...@@ -43,7 +43,7 @@ test "continue outer for loop" {
43}43}
4444
45fn testContinueOuter() !void {45fn testContinueOuter() !void {
46 var array = "aoeu";46 const array = "aoeu";
47 var counter: usize = 0;47 var counter: usize = 0;
48 outer: for (array) |_| {48 outer: for (array) |_| {
49 for (array) |_| {49 for (array) |_| {
...@@ -137,7 +137,7 @@ test "2 break statements and an else" {...@@ -137,7 +137,7 @@ test "2 break statements and an else" {
137 fn entry(t: bool, f: bool) !void {137 fn entry(t: bool, f: bool) !void {
138 var buf: [10]u8 = undefined;138 var buf: [10]u8 = undefined;
139 var ok = false;139 var ok = false;
140 ok = for (buf) |item| {140 ok = for (&buf) |*item| {
141 _ = item;141 _ = item;
142 if (f) break false;142 if (f) break false;
143 if (t) break true;143 if (t) break true;
...@@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" {...@@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" {
201201
202 const S = struct {202 const S = struct {
203 fn doTheTest(slice: []const u8) !void {203 fn doTheTest(slice: []const u8) !void {
204 var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len];204 const ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len];
205 for (ptr, 0..) |x, i| try expect(x == i + 1);205 for (ptr, 0..) |x, i| try expect(x == i + 1);
206 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);206 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);
207 }207 }
...@@ -230,6 +230,7 @@ test "for loop with else branch" {...@@ -230,6 +230,7 @@ test "for loop with else branch" {
230230
231 {231 {
232 var x = [_]u32{ 1, 2 };232 var x = [_]u32{ 1, 2 };
233 _ = &x;
233 const q = for (x) |y| {234 const q = for (x) |y| {
234 if ((y & 1) != 0) continue;235 if ((y & 1) != 0) continue;
235 break y * 2;236 break y * 2;
...@@ -238,6 +239,7 @@ test "for loop with else branch" {...@@ -238,6 +239,7 @@ test "for loop with else branch" {
238 }239 }
239 {240 {
240 var x = [_]u32{ 1, 2 };241 var x = [_]u32{ 1, 2 };
242 _ = &x;
241 const q = for (x) |y| {243 const q = for (x) |y| {
242 if ((y & 1) != 0) continue;244 if ((y & 1) != 0) continue;
243 break y * 2;245 break y * 2;
...@@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" {...@@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" {
310312
311 const slice: []const u8 = "blah";313 const slice: []const u8 = "blah";
312 var start: usize = 0;314 var start: usize = 0;
315 _ = &start;
313316
314 for (slice, start..4, 1..5) |a, b, c| {317 for (slice, start..4, 1..5) |a, b, c| {
315 if (a == 'b') {318 if (a == 'b') {
...@@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" {...@@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" {
394397
395 const comptime_slice = "hello";398 const comptime_slice = "hello";
396 var runtime_i: usize = 3;399 var runtime_i: usize = 3;
400 _ = &runtime_i;
397401
398 const S = struct {402 const S = struct {
399 var ok: usize = 0;403 var ok: usize = 0;
...@@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" {...@@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" {
424428
425 var runtime_slice = "hello";429 var runtime_slice = "hello";
426 var runtime_i: usize = 3;430 var runtime_i: usize = 3;
431 _ = &runtime_i;
427432
428 const S = struct {433 const S = struct {
429 var ok: usize = 0;434 var ok: usize = 0;
...@@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" {...@@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" {
484489
485 {490 {
486 var cond = false;491 var cond = false;
487 var opt = for (0..1) |_| {492 _ = &cond;
493 const opt = for (0..1) |_| {
488 if (cond) break cond;494 if (cond) break cond;
489 } else null;495 } else null;
490 try expectEqual(@as(?bool, null), opt);496 try expectEqual(@as(?bool, null), opt);
491 }497 }
492 {498 {
493 var cond = true;499 var cond = true;
494 var opt = for (0..1) |_| {500 _ = &cond;
501 const opt = for (0..1) |_| {
495 if (cond) break cond;502 if (cond) break cond;
496 } else null;503 } else null;
497 try expectEqual(@as(?bool, true), opt);504 try expectEqual(@as(?bool, true), opt);
test/behavior/generics.zig+2
...@@ -102,6 +102,7 @@ test "type constructed by comptime function call" {...@@ -102,6 +102,7 @@ test "type constructed by comptime function call" {
102102
103fn SimpleList(comptime L: usize) type {103fn SimpleList(comptime L: usize) type {
104 var mutable_T = u8;104 var mutable_T = u8;
105 _ = &mutable_T;
105 const T = mutable_T;106 const T = mutable_T;
106 return struct {107 return struct {
107 array: [L]T,108 array: [L]T,
...@@ -238,6 +239,7 @@ test "function parameter is generic" {...@@ -238,6 +239,7 @@ test "function parameter is generic" {
238 }239 }
239 };240 };
240 var rng: u32 = 2;241 var rng: u32 = 2;
242 _ = &rng;
241 S.init(rng, S.fill);243 S.init(rng, S.fill);
242}244}
243245
test/behavior/if.zig+12-5
...@@ -61,6 +61,7 @@ test "unwrap mutable global var" {...@@ -61,6 +61,7 @@ test "unwrap mutable global var" {
61test "labeled break inside comptime if inside runtime if" {61test "labeled break inside comptime if inside runtime if" {
62 var answer: i32 = 0;62 var answer: i32 = 0;
63 var c = true;63 var c = true;
64 _ = &c;
64 if (c) {65 if (c) {
65 answer = if (true) blk: {66 answer = if (true) blk: {
66 break :blk @as(i32, 42);67 break :blk @as(i32, 42);
...@@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" {...@@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" {
73 const Num = enum { One, Two };74 const Num = enum { One, Two };
7475
75 var t = true;76 var t = true;
77 _ = &t;
76 const x = if (t) Num.Two else unreachable;78 const x = if (t) Num.Two else unreachable;
77 try expect(x == .Two);79 try expect(x == .Two);
78}80}
...@@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" {...@@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" {
103 try expect(x == 2);105 try expect(x == 2);
104106
105 var b = true;107 var b = true;
108 _ = &b;
106 const y: i32 = if (b) 1 else 2;109 const y: i32 = if (b) 1 else 2;
107 try expect(y == 1);110 try expect(y == 1);
108 }111 }
...@@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" {...@@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" {
118121
119 var self: []const u8 = "abcdef";122 var self: []const u8 = "abcdef";
120 var index: usize = 0;123 var index: usize = 0;
121 var left_index = (index << 1) + 1;124 _ = .{ &self, &index };
122 var right_index = left_index + 1;125 const left_index = (index << 1) + 1;
123 var left = if (left_index < self.len) self[left_index] else null;126 const right_index = left_index + 1;
124 var right = if (right_index < self.len) self[right_index] else null;127 const left = if (left_index < self.len) self[left_index] else null;
128 const right = if (right_index < self.len) self[right_index] else null;
125 try expect(left_index < self.len);129 try expect(left_index < self.len);
126 try expect(right_index < self.len);130 try expect(right_index < self.len);
127 try expect(left.? == 98);131 try expect(left.? == 98);
...@@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti...@@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti
135139
136 const A = struct { b: u64, c: u64 };140 const A = struct { b: u64, c: u64 };
137 var d: bool = true;141 var d: bool = true;
142 _ = &d;
138 const e = if (d) A{ .b = 15, .c = 30 } else null;143 const e = if (d) A{ .b = 15, .c = 30 } else null;
139 try expect(e != null);144 try expect(e != null);
140}145}
...@@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti...@@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti
142test "result location with inferred type ends up being pointer to comptime_int" {147test "result location with inferred type ends up being pointer to comptime_int" {
143 var a: ?u32 = 1234;148 var a: ?u32 = 1234;
144 var b: u32 = 2000;149 var b: u32 = 2000;
145 var c = if (a) |d| blk: {150 _ = .{ &a, &b };
151 const c = if (a) |d| blk: {
146 if (d < b) break :blk @as(u32, 1);152 if (d < b) break :blk @as(u32, 1);
147 break :blk 0;153 break :blk 0;
148 } else @as(u32, 0);154 } else @as(u32, 0);
...@@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int"...@@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int"
152test "if-@as-if chain" {158test "if-@as-if chain" {
153 var fast = true;159 var fast = true;
154 var very_fast = false;160 var very_fast = false;
161 _ = .{ &fast, &very_fast };
155162
156 const num_frames = if (fast)163 const num_frames = if (fast)
157 @as(u32, if (very_fast) 16 else 4)164 @as(u32, if (very_fast) 16 else 4)
test/behavior/inline_switch.zig+8
...@@ -22,6 +22,7 @@ test "inline prong ranges" {...@@ -22,6 +22,7 @@ test "inline prong ranges" {
22 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO22 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2323
24 var x: usize = 0;24 var x: usize = 0;
25 _ = &x;
25 switch (x) {26 switch (x) {
26 inline 0...20, 24 => |item| {27 inline 0...20, 24 => |item| {
27 if (item > 25) @compileError("bad");28 if (item > 25) @compileError("bad");
...@@ -36,6 +37,7 @@ test "inline switch enums" {...@@ -36,6 +37,7 @@ test "inline switch enums" {
36 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO37 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3738
38 var x: E = .a;39 var x: E = .a;
40 _ = &x;
39 switch (x) {41 switch (x) {
40 inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"),42 inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"),
41 inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"),43 inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"),
...@@ -49,6 +51,7 @@ test "inline switch unions" {...@@ -49,6 +51,7 @@ test "inline switch unions" {
49 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO51 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
5052
51 var x: U = .a;53 var x: U = .a;
54 _ = &x;
52 switch (x) {55 switch (x) {
53 inline .a, .b => |aorb, tag| {56 inline .a, .b => |aorb, tag| {
54 if (tag == .a) {57 if (tag == .a) {
...@@ -74,6 +77,7 @@ test "inline else bool" {...@@ -74,6 +77,7 @@ test "inline else bool" {
74 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO77 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7578
76 var a = true;79 var a = true;
80 _ = &a;
77 switch (a) {81 switch (a) {
78 true => {},82 true => {},
79 inline else => |val| if (val != false) @compileError("bad"),83 inline else => |val| if (val != false) @compileError("bad"),
...@@ -86,6 +90,7 @@ test "inline else error" {...@@ -86,6 +90,7 @@ test "inline else error" {
8690
87 const Err = error{ a, b, c };91 const Err = error{ a, b, c };
88 var a = Err.a;92 var a = Err.a;
93 _ = &a;
89 switch (a) {94 switch (a) {
90 error.a => {},95 error.a => {},
91 inline else => |val| comptime if (val == error.a) @compileError("bad"),96 inline else => |val| comptime if (val == error.a) @compileError("bad"),
...@@ -98,6 +103,7 @@ test "inline else enum" {...@@ -98,6 +103,7 @@ test "inline else enum" {
98103
99 const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 };104 const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 };
100 var a: E2 = .a;105 var a: E2 = .a;
106 _ = &a;
101 switch (a) {107 switch (a) {
102 .a, .b => {},108 .a, .b => {},
103 inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"),109 inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"),
...@@ -109,6 +115,7 @@ test "inline else int with gaps" {...@@ -109,6 +115,7 @@ test "inline else int with gaps" {
109 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO115 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
110116
111 var a: u8 = 0;117 var a: u8 = 0;
118 _ = &a;
112 switch (a) {119 switch (a) {
113 1...125, 128...254 => {},120 1...125, 128...254 => {},
114 inline else => |val| {121 inline else => |val| {
...@@ -126,6 +133,7 @@ test "inline else int all values" {...@@ -126,6 +133,7 @@ test "inline else int all values" {
126 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO133 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
127134
128 var a: u2 = 0;135 var a: u2 = 0;
136 _ = &a;
129 switch (a) {137 switch (a) {
130 inline else => |val| {138 inline else => |val| {
131 if (val != 0 and139 if (val != 0 and
test/behavior/int128.zig+3
...@@ -39,6 +39,7 @@ test "undefined 128 bit int" {...@@ -39,6 +39,7 @@ test "undefined 128 bit int" {
3939
40 var undef: u128 = undefined;40 var undef: u128 = undefined;
41 var undef_signed: i128 = undefined;41 var undef_signed: i128 = undefined;
42 _ = .{ &undef, &undef_signed };
42 try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef);43 try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef);
43}44}
4445
...@@ -73,6 +74,7 @@ test "truncate int128" {...@@ -73,6 +74,7 @@ test "truncate int128" {
7374
74 {75 {
75 var buff: u128 = maxInt(u128);76 var buff: u128 = maxInt(u128);
77 _ = &buff;
76 try expect(@as(u64, @truncate(buff)) == maxInt(u64));78 try expect(@as(u64, @truncate(buff)) == maxInt(u64));
77 try expect(@as(u90, @truncate(buff)) == maxInt(u90));79 try expect(@as(u90, @truncate(buff)) == maxInt(u90));
78 try expect(@as(u128, @truncate(buff)) == maxInt(u128));80 try expect(@as(u128, @truncate(buff)) == maxInt(u128));
...@@ -80,6 +82,7 @@ test "truncate int128" {...@@ -80,6 +82,7 @@ test "truncate int128" {
8082
81 {83 {
82 var buff: i128 = maxInt(i128);84 var buff: i128 = maxInt(i128);
85 _ = &buff;
83 try expect(@as(i64, @truncate(buff)) == -1);86 try expect(@as(i64, @truncate(buff)) == -1);
84 try expect(@as(i90, @truncate(buff)) == -1);87 try expect(@as(i90, @truncate(buff)) == -1);
85 try expect(@as(i128, @truncate(buff)) == maxInt(i128));88 try expect(@as(i128, @truncate(buff)) == maxInt(i128));
test/behavior/int_comparison_elision.zig+1
...@@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void {...@@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void {
30 const max = maxInt(T);30 const max = maxInt(T);
3131
32 var runtime_val: T = undefined;32 var runtime_val: T = undefined;
33 _ = &runtime_val;
3334
34 if (min > runtime_val) @compileError("analyzed impossible branch");35 if (min > runtime_val) @compileError("analyzed impossible branch");
35 if (min <= runtime_val) {} else @compileError("analyzed impossible branch");36 if (min <= runtime_val) {} else @compileError("analyzed impossible branch");
test/behavior/int_div.zig+2
...@@ -100,11 +100,13 @@ test "large integer division" {...@@ -100,11 +100,13 @@ test "large integer division" {
100 {100 {
101 var numerator: u256 = 99999999999999999997315645440;101 var numerator: u256 = 99999999999999999997315645440;
102 var divisor: u256 = 10000000000000000000000000000;102 var divisor: u256 = 10000000000000000000000000000;
103 _ = .{ &numerator, &divisor };
103 try expect(numerator / divisor == 9);104 try expect(numerator / divisor == 9);
104 }105 }
105 {106 {
106 var numerator: u256 = 99999999999999999999000000000000000000000;107 var numerator: u256 = 99999999999999999999000000000000000000000;
107 var divisor: u256 = 10000000000000000000000000000000000000000;108 var divisor: u256 = 10000000000000000000000000000000000000000;
109 _ = .{ &numerator, &divisor };
108 try expect(numerator / divisor == 9);110 try expect(numerator / divisor == 9);
109 }111 }
110}112}
test/behavior/math.zig+53-5
...@@ -624,7 +624,8 @@ const DivResult = struct {...@@ -624,7 +624,8 @@ const DivResult = struct {
624624
625test "bit shift a u1" {625test "bit shift a u1" {
626 var x: u1 = 1;626 var x: u1 = 1;
627 var y = x << 0;627 _ = &x;
628 const y = x << 0;
628 try expect(y == 1);629 try expect(y == 1);
629}630}
630631
...@@ -692,7 +693,8 @@ test "128-bit multiplication" {...@@ -692,7 +693,8 @@ test "128-bit multiplication" {
692 {693 {
693 var a: u128 = 0xffffffffffffffff;694 var a: u128 = 0xffffffffffffffff;
694 var b: u128 = 100;695 var b: u128 = 100;
695 var c = a * b;696 _ = .{ &a, &b };
697 const c = a * b;
696 try expect(c == 0x63ffffffffffffff9c);698 try expect(c == 0x63ffffffffffffff9c);
697 }699 }
698}700}
...@@ -704,18 +706,21 @@ test "@addWithOverflow" {...@@ -704,18 +706,21 @@ test "@addWithOverflow" {
704706
705 {707 {
706 var a: u8 = 250;708 var a: u8 = 250;
709 _ = &a;
707 const ov = @addWithOverflow(a, 100);710 const ov = @addWithOverflow(a, 100);
708 try expect(ov[0] == 94);711 try expect(ov[0] == 94);
709 try expect(ov[1] == 1);712 try expect(ov[1] == 1);
710 }713 }
711 {714 {
712 var a: u8 = 100;715 var a: u8 = 100;
716 _ = &a;
713 const ov = @addWithOverflow(a, 150);717 const ov = @addWithOverflow(a, 150);
714 try expect(ov[0] == 250);718 try expect(ov[0] == 250);
715 try expect(ov[1] == 0);719 try expect(ov[1] == 0);
716 }720 }
717 {721 {
718 var a: u8 = 200;722 var a: u8 = 200;
723 _ = &a;
719 var b: u8 = 99;724 var b: u8 = 99;
720 var ov = @addWithOverflow(a, b);725 var ov = @addWithOverflow(a, b);
721 try expect(ov[0] == 43);726 try expect(ov[0] == 43);
...@@ -729,6 +734,7 @@ test "@addWithOverflow" {...@@ -729,6 +734,7 @@ test "@addWithOverflow" {
729 {734 {
730 var a: usize = 6;735 var a: usize = 6;
731 var b: usize = 6;736 var b: usize = 6;
737 _ = .{ &a, &b };
732 const ov = @addWithOverflow(a, b);738 const ov = @addWithOverflow(a, b);
733 try expect(ov[0] == 12);739 try expect(ov[0] == 12);
734 try expect(ov[1] == 0);740 try expect(ov[1] == 0);
...@@ -737,6 +743,7 @@ test "@addWithOverflow" {...@@ -737,6 +743,7 @@ test "@addWithOverflow" {
737 {743 {
738 var a: isize = -6;744 var a: isize = -6;
739 var b: isize = -6;745 var b: isize = -6;
746 _ = .{ &a, &b };
740 const ov = @addWithOverflow(a, b);747 const ov = @addWithOverflow(a, b);
741 try expect(ov[0] == -12);748 try expect(ov[0] == -12);
742 try expect(ov[1] == 0);749 try expect(ov[1] == 0);
...@@ -772,18 +779,21 @@ test "basic @mulWithOverflow" {...@@ -772,18 +779,21 @@ test "basic @mulWithOverflow" {
772779
773 {780 {
774 var a: u8 = 86;781 var a: u8 = 86;
782 _ = &a;
775 const ov = @mulWithOverflow(a, 3);783 const ov = @mulWithOverflow(a, 3);
776 try expect(ov[0] == 2);784 try expect(ov[0] == 2);
777 try expect(ov[1] == 1);785 try expect(ov[1] == 1);
778 }786 }
779 {787 {
780 var a: u8 = 85;788 var a: u8 = 85;
789 _ = &a;
781 const ov = @mulWithOverflow(a, 3);790 const ov = @mulWithOverflow(a, 3);
782 try expect(ov[0] == 255);791 try expect(ov[0] == 255);
783 try expect(ov[1] == 0);792 try expect(ov[1] == 0);
784 }793 }
785794
786 var a: u8 = 123;795 var a: u8 = 123;
796 _ = &a;
787 var b: u8 = 2;797 var b: u8 = 2;
788 var ov = @mulWithOverflow(a, b);798 var ov = @mulWithOverflow(a, b);
789 try expect(ov[0] == 246);799 try expect(ov[0] == 246);
...@@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" {...@@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" {
802812
803 {813 {
804 var a: u5 = 3;814 var a: u5 = 3;
815 _ = &a;
805 var b: u5 = 10;816 var b: u5 = 10;
806 var ov = @mulWithOverflow(a, b);817 var ov = @mulWithOverflow(a, b);
807 try expect(ov[0] == 30);818 try expect(ov[0] == 30);
...@@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" {...@@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" {
815826
816 {827 {
817 var a: i5 = 3;828 var a: i5 = 3;
829 _ = &a;
818 var b: i5 = -5;830 var b: i5 = -5;
819 var ov = @mulWithOverflow(a, b);831 var ov = @mulWithOverflow(a, b);
820 try expect(ov[0] == -15);832 try expect(ov[0] == -15);
...@@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" {...@@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" {
828840
829 {841 {
830 var a: u8 = 3;842 var a: u8 = 3;
843 _ = &a;
831 var b: u8 = 85;844 var b: u8 = 85;
832845
833 var ov = @mulWithOverflow(a, b);846 var ov = @mulWithOverflow(a, b);
...@@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" {...@@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" {
842855
843 {856 {
844 var a: i8 = 3;857 var a: i8 = 3;
858 _ = &a;
845 var b: i8 = -42;859 var b: i8 = -42;
846 var ov = @mulWithOverflow(a, b);860 var ov = @mulWithOverflow(a, b);
847 try expect(ov[0] == -126);861 try expect(ov[0] == -126);
...@@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" {...@@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" {
855869
856 {870 {
857 var a: u14 = 3;871 var a: u14 = 3;
872 _ = &a;
858 var b: u14 = 0x1555;873 var b: u14 = 0x1555;
859 var ov = @mulWithOverflow(a, b);874 var ov = @mulWithOverflow(a, b);
860 try expect(ov[0] == 0x3fff);875 try expect(ov[0] == 0x3fff);
...@@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" {...@@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" {
868883
869 {884 {
870 var a: i14 = 3;885 var a: i14 = 3;
886 _ = &a;
871 var b: i14 = -0xaaa;887 var b: i14 = -0xaaa;
872 var ov = @mulWithOverflow(a, b);888 var ov = @mulWithOverflow(a, b);
873 try expect(ov[0] == -0x1ffe);889 try expect(ov[0] == -0x1ffe);
...@@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" {...@@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" {
880896
881 {897 {
882 var a: u16 = 3;898 var a: u16 = 3;
899 _ = &a;
883 var b: u16 = 0x5555;900 var b: u16 = 0x5555;
884 var ov = @mulWithOverflow(a, b);901 var ov = @mulWithOverflow(a, b);
885 try expect(ov[0] == 0xffff);902 try expect(ov[0] == 0xffff);
...@@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" {...@@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" {
893910
894 {911 {
895 var a: i16 = 3;912 var a: i16 = 3;
913 _ = &a;
896 var b: i16 = -0x2aaa;914 var b: i16 = -0x2aaa;
897 var ov = @mulWithOverflow(a, b);915 var ov = @mulWithOverflow(a, b);
898 try expect(ov[0] == -0x7ffe);916 try expect(ov[0] == -0x7ffe);
...@@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" {...@@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" {
906924
907 {925 {
908 var a: u30 = 3;926 var a: u30 = 3;
927 _ = &a;
909 var b: u30 = 0x15555555;928 var b: u30 = 0x15555555;
910 var ov = @mulWithOverflow(a, b);929 var ov = @mulWithOverflow(a, b);
911 try expect(ov[0] == 0x3fffffff);930 try expect(ov[0] == 0x3fffffff);
...@@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" {...@@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" {
919938
920 {939 {
921 var a: i30 = 3;940 var a: i30 = 3;
941 _ = &a;
922 var b: i30 = -0xaaaaaaa;942 var b: i30 = -0xaaaaaaa;
923 var ov = @mulWithOverflow(a, b);943 var ov = @mulWithOverflow(a, b);
924 try expect(ov[0] == -0x1ffffffe);944 try expect(ov[0] == -0x1ffffffe);
...@@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" {...@@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" {
932952
933 {953 {
934 var a: u32 = 3;954 var a: u32 = 3;
955 _ = &a;
935 var b: u32 = 0x55555555;956 var b: u32 = 0x55555555;
936 var ov = @mulWithOverflow(a, b);957 var ov = @mulWithOverflow(a, b);
937 try expect(ov[0] == 0xffffffff);958 try expect(ov[0] == 0xffffffff);
...@@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" {...@@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" {
945966
946 {967 {
947 var a: i32 = 3;968 var a: i32 = 3;
969 _ = &a;
948 var b: i32 = -0x2aaaaaaa;970 var b: i32 = -0x2aaaaaaa;
949 var ov = @mulWithOverflow(a, b);971 var ov = @mulWithOverflow(a, b);
950 try expect(ov[0] == -0x7ffffffe);972 try expect(ov[0] == -0x7ffffffe);
...@@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" {...@@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" {
967989
968 {990 {
969 var a: u62 = 3;991 var a: u62 = 3;
992 _ = &a;
970 var b: u62 = 0x1555555555555555;993 var b: u62 = 0x1555555555555555;
971 var ov = @mulWithOverflow(a, b);994 var ov = @mulWithOverflow(a, b);
972 try expect(ov[0] == 0x3fffffffffffffff);995 try expect(ov[0] == 0x3fffffffffffffff);
...@@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" {...@@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" {
9801003
981 {1004 {
982 var a: i62 = 3;1005 var a: i62 = 3;
1006 _ = &a;
983 var b: i62 = -0xaaaaaaaaaaaaaaa;1007 var b: i62 = -0xaaaaaaaaaaaaaaa;
984 var ov = @mulWithOverflow(a, b);1008 var ov = @mulWithOverflow(a, b);
985 try expect(ov[0] == -0x1ffffffffffffffe);1009 try expect(ov[0] == -0x1ffffffffffffffe);
...@@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" {...@@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" {
9931017
994 {1018 {
995 var a: u64 = 3;1019 var a: u64 = 3;
1020 _ = &a;
996 var b: u64 = 0x5555555555555555;1021 var b: u64 = 0x5555555555555555;
997 var ov = @mulWithOverflow(a, b);1022 var ov = @mulWithOverflow(a, b);
998 try expect(ov[0] == 0xffffffffffffffff);1023 try expect(ov[0] == 0xffffffffffffffff);
...@@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" {...@@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" {
10061031
1007 {1032 {
1008 var a: i64 = 3;1033 var a: i64 = 3;
1034 _ = &a;
1009 var b: i64 = -0x2aaaaaaaaaaaaaaa;1035 var b: i64 = -0x2aaaaaaaaaaaaaaa;
1010 var ov = @mulWithOverflow(a, b);1036 var ov = @mulWithOverflow(a, b);
1011 try expect(ov[0] == -0x7ffffffffffffffe);1037 try expect(ov[0] == -0x7ffffffffffffffe);
...@@ -1025,12 +1051,14 @@ test "@subWithOverflow" {...@@ -1025,12 +1051,14 @@ test "@subWithOverflow" {
10251051
1026 {1052 {
1027 var a: u8 = 1;1053 var a: u8 = 1;
1054 _ = &a;
1028 const ov = @subWithOverflow(a, 2);1055 const ov = @subWithOverflow(a, 2);
1029 try expect(ov[0] == 255);1056 try expect(ov[0] == 255);
1030 try expect(ov[1] == 1);1057 try expect(ov[1] == 1);
1031 }1058 }
1032 {1059 {
1033 var a: u8 = 1;1060 var a: u8 = 1;
1061 _ = &a;
1034 const ov = @subWithOverflow(a, 1);1062 const ov = @subWithOverflow(a, 1);
1035 try expect(ov[0] == 0);1063 try expect(ov[0] == 0);
1036 try expect(ov[1] == 0);1064 try expect(ov[1] == 0);
...@@ -1038,6 +1066,7 @@ test "@subWithOverflow" {...@@ -1038,6 +1066,7 @@ test "@subWithOverflow" {
10381066
1039 {1067 {
1040 var a: u8 = 1;1068 var a: u8 = 1;
1069 _ = &a;
1041 var b: u8 = 2;1070 var b: u8 = 2;
1042 var ov = @subWithOverflow(a, b);1071 var ov = @subWithOverflow(a, b);
1043 try expect(ov[0] == 255);1072 try expect(ov[0] == 255);
...@@ -1051,6 +1080,7 @@ test "@subWithOverflow" {...@@ -1051,6 +1080,7 @@ test "@subWithOverflow" {
1051 {1080 {
1052 var a: usize = 6;1081 var a: usize = 6;
1053 var b: usize = 6;1082 var b: usize = 6;
1083 _ = .{ &a, &b };
1054 const ov = @subWithOverflow(a, b);1084 const ov = @subWithOverflow(a, b);
1055 try expect(ov[0] == 0);1085 try expect(ov[0] == 0);
1056 try expect(ov[1] == 0);1086 try expect(ov[1] == 0);
...@@ -1059,6 +1089,7 @@ test "@subWithOverflow" {...@@ -1059,6 +1089,7 @@ test "@subWithOverflow" {
1059 {1089 {
1060 var a: isize = -6;1090 var a: isize = -6;
1061 var b: isize = -6;1091 var b: isize = -6;
1092 _ = .{ &a, &b };
1062 const ov = @subWithOverflow(a, b);1093 const ov = @subWithOverflow(a, b);
1063 try expect(ov[0] == 0);1094 try expect(ov[0] == 0);
1064 try expect(ov[1] == 0);1095 try expect(ov[1] == 0);
...@@ -1072,6 +1103,7 @@ test "@shlWithOverflow" {...@@ -1072,6 +1103,7 @@ test "@shlWithOverflow" {
10721103
1073 {1104 {
1074 var a: u4 = 2;1105 var a: u4 = 2;
1106 _ = &a;
1075 var b: u2 = 1;1107 var b: u2 = 1;
1076 var ov = @shlWithOverflow(a, b);1108 var ov = @shlWithOverflow(a, b);
1077 try expect(ov[0] == 4);1109 try expect(ov[0] == 4);
...@@ -1085,6 +1117,7 @@ test "@shlWithOverflow" {...@@ -1085,6 +1117,7 @@ test "@shlWithOverflow" {
10851117
1086 {1118 {
1087 var a: i9 = 127;1119 var a: i9 = 127;
1120 _ = &a;
1088 var b: u4 = 1;1121 var b: u4 = 1;
1089 var ov = @shlWithOverflow(a, b);1122 var ov = @shlWithOverflow(a, b);
1090 try expect(ov[0] == 254);1123 try expect(ov[0] == 254);
...@@ -1108,6 +1141,7 @@ test "@shlWithOverflow" {...@@ -1108,6 +1141,7 @@ test "@shlWithOverflow" {
1108 }1141 }
1109 {1142 {
1110 var a: u16 = 0b0000_0000_0000_0011;1143 var a: u16 = 0b0000_0000_0000_0011;
1144 _ = &a;
1111 var b: u4 = 15;1145 var b: u4 = 15;
1112 var ov = @shlWithOverflow(a, b);1146 var ov = @shlWithOverflow(a, b);
1113 try expect(ov[0] == 0b1000_0000_0000_0000);1147 try expect(ov[0] == 0b1000_0000_0000_0000);
...@@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" {...@@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" {
11241158
1125 {1159 {
1126 var a: u0 = 0;1160 var a: u0 = 0;
1161 _ = &a;
1127 const ov = @addWithOverflow(a, 0);1162 const ov = @addWithOverflow(a, 0);
1128 try expect(ov[1] == 0);1163 try expect(ov[1] == 0);
1129 try expect(ov[1] == 0);1164 try expect(ov[1] == 0);
1130 }1165 }
1131 {1166 {
1132 var a: u0 = 0;1167 var a: u0 = 0;
1168 _ = &a;
1133 const ov = @subWithOverflow(a, 0);1169 const ov = @subWithOverflow(a, 0);
1134 try expect(ov[1] == 0);1170 try expect(ov[1] == 0);
1135 try expect(ov[1] == 0);1171 try expect(ov[1] == 0);
1136 }1172 }
1137 {1173 {
1138 var a: u0 = 0;1174 var a: u0 = 0;
1175 _ = &a;
1139 const ov = @mulWithOverflow(a, 0);1176 const ov = @mulWithOverflow(a, 0);
1140 try expect(ov[1] == 0);1177 try expect(ov[1] == 0);
1141 try expect(ov[1] == 0);1178 try expect(ov[1] == 0);
1142 }1179 }
1143 {1180 {
1144 var a: u0 = 0;1181 var a: u0 = 0;
1182 _ = &a;
1145 const ov = @shlWithOverflow(a, 0);1183 const ov = @shlWithOverflow(a, 0);
1146 try expect(ov[1] == 0);1184 try expect(ov[1] == 0);
1147 try expect(ov[1] == 0);1185 try expect(ov[1] == 0);
...@@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and...@@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and
1157 try expect(-6 % 3 == 0);1195 try expect(-6 % 3 == 0);
11581196
1159 var undef: i32 = undefined;1197 var undef: i32 = undefined;
1198 _ = &undef;
1160 if (0 % undef != 0) {1199 if (0 % undef != 0) {
1161 @compileError("0 as numerator should return comptime zero independent of denominator");1200 @compileError("0 as numerator should return comptime zero independent of denominator");
1162 }1201 }
...@@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" {...@@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" {
1183 fn doTheTest() !void {1222 fn doTheTest() !void {
1184 {1223 {
1185 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;1224 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
1225 _ = &f;
1186 try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);1226 try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);
1187 }1227 }
1188 {1228 {
1189 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;1229 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
1230 _ = &f;
1190 try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even1231 try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even
1191 }1232 }
1192 {1233 {
1193 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;1234 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
1235 _ = &f;
1194 try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);1236 try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
1195 }1237 }
1196 {1238 {
1197 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;1239 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
1240 _ = &f;
1198 try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);1241 try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);
1199 }1242 }
1200 const exp2ft = [_]f64{1243 const exp2ft = [_]f64{
...@@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" {...@@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" {
1294 fn doTheTest() !void {1337 fn doTheTest() !void {
1295 var x: u0 = 0;1338 var x: u0 = 0;
1296 var y: u0 = 0;1339 var y: u0 = 0;
1340 _ = .{ &x, &y };
1297 try expectEqual(@as(u0, 0), x << 0);1341 try expectEqual(@as(u0, 0), x << 0);
1298 try expectEqual(@as(u0, 0), x >> 0);1342 try expectEqual(@as(u0, 0), x >> 0);
1299 try expectEqual(@as(u0, 0), x << y);1343 try expectEqual(@as(u0, 0), x << y);
...@@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" {...@@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" {
13101354
1311test "comptime float rem int" {1355test "comptime float rem int" {
1312 comptime {1356 comptime {
1313 var x = @as(f32, 1) % 2;1357 const x = @as(f32, 1) % 2;
1314 try expect(x == 1.0);1358 try expect(x == 1.0);
1315 }1359 }
1316}1360}
...@@ -1511,7 +1555,8 @@ test "vector integer addition" {...@@ -1511,7 +1555,8 @@ test "vector integer addition" {
1511 fn doTheTest() !void {1555 fn doTheTest() !void {
1512 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };1556 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
1513 var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };1557 var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
1514 var result = a + b;1558 _ = .{ &a, &b };
1559 const result = a + b;
1515 var result_array: [4]i32 = result;1560 var result_array: [4]i32 = result;
1516 const expected = [_]i32{ 6, 8, 10, 12 };1561 const expected = [_]i32{ 6, 8, 10, 12 };
1517 try expectEqualSlices(i32, &expected, &result_array);1562 try expectEqualSlices(i32, &expected, &result_array);
...@@ -1552,6 +1597,7 @@ test "NaN comparison f80" {...@@ -1552,6 +1597,7 @@ test "NaN comparison f80" {
1552fn testNanEqNan(comptime F: type) !void {1597fn testNanEqNan(comptime F: type) !void {
1553 var nan1 = math.nan(F);1598 var nan1 = math.nan(F);
1554 var nan2 = math.nan(F);1599 var nan2 = math.nan(F);
1600 _ = .{ &nan1, &nan2 };
1555 try expect(nan1 != nan2);1601 try expect(nan1 != nan2);
1556 try expect(!(nan1 == nan2));1602 try expect(!(nan1 == nan2));
1557 try expect(!(nan1 > nan2));1603 try expect(!(nan1 > nan2));
...@@ -1571,6 +1617,7 @@ test "vector comparison" {...@@ -1571,6 +1617,7 @@ test "vector comparison" {
1571 fn doTheTest() !void {1617 fn doTheTest() !void {
1572 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };1618 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
1573 var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };1619 var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
1620 _ = .{ &a, &b };
1574 try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));1621 try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
1575 try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));1622 try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
1576 try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));1623 try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
...@@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" {...@@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" {
1609 fn testOne(comptime T: type) !void {1656 fn testOne(comptime T: type) !void {
1610 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);1657 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
1611 var as_fp_val = -@as(T, 0.0);1658 var as_fp_val = -@as(T, 0.0);
1612 var as_uint_val = @as(ST, @bitCast(as_fp_val));1659 _ = &as_fp_val;
1660 const as_uint_val: ST = @bitCast(as_fp_val);
1613 // Ensure the sign bit is set.1661 // Ensure the sign bit is set.
1614 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);1662 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
1615 }1663 }
test/behavior/maximum_minimum.zig+23-6
...@@ -15,6 +15,7 @@ test "@max" {...@@ -15,6 +15,7 @@ test "@max" {
15 var x: i32 = 10;15 var x: i32 = 10;
16 var y: f32 = 0.68;16 var y: f32 = 0.68;
17 var nan: f32 = std.math.nan(f32);17 var nan: f32 = std.math.nan(f32);
18 _ = .{ &x, &y, &nan };
18 try expect(@as(i32, 10) == @max(@as(i32, -3), x));19 try expect(@as(i32, 10) == @max(@as(i32, -3), x));
19 try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y));20 try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y));
20 try expect(y == @max(nan, y));21 try expect(y == @max(nan, y));
...@@ -38,17 +39,20 @@ test "@max on vectors" {...@@ -38,17 +39,20 @@ test "@max on vectors" {
38 fn doTheTest() !void {39 fn doTheTest() !void {
39 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };40 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
40 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };41 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
41 var x = @max(a, b);42 const x = @max(a, b);
43 _ = .{ &a, &b };
42 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 }));44 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 }));
4345
44 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };46 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };
45 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };47 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };
46 var y = @max(c, d);48 const y = @max(c, d);
49 _ = .{ &c, &d };
47 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 }));50 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 }));
4851
49 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };52 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };
50 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };53 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };
51 var z = @max(e, f);54 const z = @max(e, f);
55 _ = .{ &e, &f };
52 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));56 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));
53 }57 }
54 };58 };
...@@ -66,6 +70,7 @@ test "@min" {...@@ -66,6 +70,7 @@ test "@min" {
66 var x: i32 = 10;70 var x: i32 = 10;
67 var y: f32 = 0.68;71 var y: f32 = 0.68;
68 var nan: f32 = std.math.nan(f32);72 var nan: f32 = std.math.nan(f32);
73 _ = .{ &x, &y, &nan };
69 try expect(@as(i32, -3) == @min(@as(i32, -3), x));74 try expect(@as(i32, -3) == @min(@as(i32, -3), x));
70 try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y));75 try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y));
71 try expect(y == @min(nan, y));76 try expect(y == @min(nan, y));
...@@ -89,17 +94,20 @@ test "@min for vectors" {...@@ -89,17 +94,20 @@ test "@min for vectors" {
89 fn doTheTest() !void {94 fn doTheTest() !void {
90 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };95 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
91 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };96 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
92 var x = @min(a, b);97 _ = .{ &a, &b };
98 const x = @min(a, b);
93 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 }));99 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 }));
94100
95 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };101 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };
96 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };102 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };
97 var y = @min(c, d);103 _ = .{ &c, &d };
104 const y = @min(c, d);
98 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 }));105 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 }));
99106
100 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };107 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };
101 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };108 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };
102 var z = @max(e, f);109 _ = .{ &e, &f };
110 const z = @max(e, f);
103 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));111 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));
104 }112 }
105 };113 };
...@@ -119,6 +127,7 @@ test "@min/max for floats" {...@@ -119,6 +127,7 @@ test "@min/max for floats" {
119 fn doTheTest(comptime T: type) !void {127 fn doTheTest(comptime T: type) !void {
120 var x: T = -3.14;128 var x: T = -3.14;
121 var y: T = 5.27;129 var y: T = 5.27;
130 _ = .{ &x, &y };
122 try expectEqual(x, @min(x, y));131 try expectEqual(x, @min(x, y));
123 try expectEqual(x, @min(y, x));132 try expectEqual(x, @min(y, x));
124 try expectEqual(y, @max(x, y));133 try expectEqual(y, @max(x, y));
...@@ -126,6 +135,7 @@ test "@min/max for floats" {...@@ -126,6 +135,7 @@ test "@min/max for floats" {
126135
127 if (T != comptime_float) {136 if (T != comptime_float) {
128 var nan: T = std.math.nan(T);137 var nan: T = std.math.nan(T);
138 _ = &nan;
129 try expectEqual(y, @max(nan, y));139 try expectEqual(y, @max(nan, y));
130 try expectEqual(y, @max(y, nan));140 try expectEqual(y, @max(y, nan));
131 }141 }
...@@ -175,6 +185,7 @@ test "@min/@max notices bounds" {...@@ -175,6 +185,7 @@ test "@min/@max notices bounds" {
175 var x: u16 = 20;185 var x: u16 = 20;
176 const y = 30;186 const y = 30;
177 var z: u32 = 100;187 var z: u32 = 100;
188 _ = .{ &x, &z };
178 const min = @min(x, y, z);189 const min = @min(x, y, z);
179 const max = @max(x, y, z);190 const max = @max(x, y, z);
180 try expectEqual(x, min);191 try expectEqual(x, min);
...@@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" {...@@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" {
194 var x: @Vector(2, u16) = .{ 140, 40 };205 var x: @Vector(2, u16) = .{ 140, 40 };
195 const y: @Vector(2, u64) = .{ 5, 100 };206 const y: @Vector(2, u64) = .{ 5, 100 };
196 var z: @Vector(2, u32) = .{ 10, 300 };207 var z: @Vector(2, u32) = .{ 10, 300 };
208 _ = .{ &x, &z };
197 const min = @min(x, y, z);209 const min = @min(x, y, z);
198 const max = @max(x, y, z);210 const max = @max(x, y, z);
199 try expectEqual(@Vector(2, u32){ 5, 40 }, min);211 try expectEqual(@Vector(2, u32){ 5, 40 }, min);
...@@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" {...@@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" {
224 var x: u16 = 123;236 var x: u16 = 123;
225 var y: u32 = 456;237 var y: u32 = 456;
226 var z: u8 = 10;238 var z: u8 = 10;
239 _ = .{ &x, &y, &z };
227240
228 const min = @min(x, y, z);241 const min = @min(x, y, z);
229 const max = @max(x, y, z);242 const max = @max(x, y, z);
...@@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" {...@@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" {
246 var x: @Vector(2, u16) = .{ 30, 67 };259 var x: @Vector(2, u16) = .{ 30, 67 };
247 var y: @Vector(2, u32) = .{ 20, 500 };260 var y: @Vector(2, u32) = .{ 20, 500 };
248 var z: @Vector(2, u8) = .{ 60, 15 };261 var z: @Vector(2, u8) = .{ 60, 15 };
262 _ = .{ &x, &y, &z };
249263
250 const min = @min(x, y, z);264 const min = @min(x, y, z);
251 const max = @max(x, y, z);265 const max = @max(x, y, z);
...@@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" {...@@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" {
263 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO277 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
264278
265 var x: u32 = 1_000_000;279 var x: u32 = 1_000_000;
280 _ = &x;
266 const y: u16 = undefined;281 const y: u16 = undefined;
267 // y is comptime-known, but is undef, so bounds cannot be refined using its value282 // y is comptime-known, but is undef, so bounds cannot be refined using its value
268283
...@@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known...@@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known
285 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest;300 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest;
286301
287 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };302 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };
303 _ = &x;
288 const y: @Vector(2, u16) = .{ 10, undefined };304 const y: @Vector(2, u16) = .{ 10, undefined };
289 // y is comptime-known, but an element is undef, so bounds cannot be refined using its value305 // y is comptime-known, but an element is undef, so bounds cannot be refined using its value
290306
...@@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known...@@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known
302test "@min/@max of signed and unsigned runtime integers" {318test "@min/@max of signed and unsigned runtime integers" {
303 var x: i32 = -1;319 var x: i32 = -1;
304 var y: u31 = 1;320 var y: u31 = 1;
321 _ = .{ &x, &y };
305322
306 const min = @min(x, y);323 const min = @min(x, y);
307 const max = @max(x, y);324 const max = @max(x, y);
test/behavior/memcpy.zig+1
...@@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void {...@@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void {
57 var str = "hello".*;57 var str = "hello".*;
58 var buf: [5]u8 = undefined;58 var buf: [5]u8 = undefined;
59 var len: usize = 5;59 var len: usize = 5;
60 _ = &len;
60 @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]);61 @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]);
61 try expect(buf[0] == 'h');62 try expect(buf[0] == 'h');
62 try expect(buf[1] == 'e');63 try expect(buf[1] == 'e');
test/behavior/memset.zig+5-2
...@@ -46,7 +46,8 @@ fn testMemsetSlice() !void {...@@ -46,7 +46,8 @@ fn testMemsetSlice() !void {
46 // memset slice to non-undefined, ABI size == 146 // memset slice to non-undefined, ABI size == 1
47 var array: [20]u8 = undefined;47 var array: [20]u8 = undefined;
48 var len = array.len;48 var len = array.len;
49 var slice = array[0..len];49 _ = &len;
50 const slice = array[0..len];
50 @memset(slice, 'A');51 @memset(slice, 'A');
51 try expect(slice[0] == 'A');52 try expect(slice[0] == 'A');
52 try expect(slice[11] == 'A');53 try expect(slice[11] == 'A');
...@@ -56,7 +57,8 @@ fn testMemsetSlice() !void {...@@ -56,7 +57,8 @@ fn testMemsetSlice() !void {
56 // memset slice to non-undefined, ABI size > 157 // memset slice to non-undefined, ABI size > 1
57 var array: [20]u32 = undefined;58 var array: [20]u32 = undefined;
58 var len = array.len;59 var len = array.len;
59 var slice = array[0..len];60 _ = &len;
61 const slice = array[0..len];
60 @memset(slice, 1234);62 @memset(slice, 1234);
61 try expect(slice[0] == 1234);63 try expect(slice[0] == 1234);
62 try expect(slice[11] == 1234);64 try expect(slice[11] == 1234);
...@@ -111,6 +113,7 @@ test "memset with large array element, runtime known" {...@@ -111,6 +113,7 @@ test "memset with large array element, runtime known" {
111 const A = [128]u64;113 const A = [128]u64;
112 var buf: [5]A = undefined;114 var buf: [5]A = undefined;
113 var runtime_known_element = [_]u64{0} ** 128;115 var runtime_known_element = [_]u64{0} ** 128;
116 _ = &runtime_known_element;
114 @memset(&buf, runtime_known_element);117 @memset(&buf, runtime_known_element);
115 for (buf[0]) |elem| try expect(elem == 0);118 for (buf[0]) |elem| try expect(elem == 0);
116 for (buf[1]) |elem| try expect(elem == 0);119 for (buf[1]) |elem| try expect(elem == 0);
test/behavior/muladd.zig+15-5
...@@ -21,12 +21,14 @@ fn testMulAdd() !void {...@@ -21,12 +21,14 @@ fn testMulAdd() !void {
21 var a: f32 = 5.5;21 var a: f32 = 5.5;
22 var b: f32 = 2.5;22 var b: f32 = 2.5;
23 var c: f32 = 6.25;23 var c: f32 = 6.25;
24 _ = .{ &a, &b, &c };
24 try expect(@mulAdd(f32, a, b, c) == 20);25 try expect(@mulAdd(f32, a, b, c) == 20);
25 }26 }
26 {27 {
27 var a: f64 = 5.5;28 var a: f64 = 5.5;
28 var b: f64 = 2.5;29 var b: f64 = 2.5;
29 var c: f64 = 6.25;30 var c: f64 = 6.25;
31 _ = .{ &a, &b, &c };
30 try expect(@mulAdd(f64, a, b, c) == 20);32 try expect(@mulAdd(f64, a, b, c) == 20);
31 }33 }
32}34}
...@@ -46,6 +48,7 @@ fn testMulAdd16() !void {...@@ -46,6 +48,7 @@ fn testMulAdd16() !void {
46 var a: f16 = 5.5;48 var a: f16 = 5.5;
47 var b: f16 = 2.5;49 var b: f16 = 2.5;
48 var c: f16 = 6.25;50 var c: f16 = 6.25;
51 _ = .{ &a, &b, &c };
49 try expect(@mulAdd(f16, a, b, c) == 20);52 try expect(@mulAdd(f16, a, b, c) == 20);
50}53}
5154
...@@ -65,6 +68,7 @@ fn testMulAdd80() !void {...@@ -65,6 +68,7 @@ fn testMulAdd80() !void {
65 var a: f16 = 5.5;68 var a: f16 = 5.5;
66 var b: f80 = 2.5;69 var b: f80 = 2.5;
67 var c: f80 = 6.25;70 var c: f80 = 6.25;
71 _ = .{ &a, &b, &c };
68 try expect(@mulAdd(f80, a, b, c) == 20);72 try expect(@mulAdd(f80, a, b, c) == 20);
69}73}
7074
...@@ -84,6 +88,7 @@ fn testMulAdd128() !void {...@@ -84,6 +88,7 @@ fn testMulAdd128() !void {
84 var a: f16 = 5.5;88 var a: f16 = 5.5;
85 var b: f128 = 2.5;89 var b: f128 = 2.5;
86 var c: f128 = 6.25;90 var c: f128 = 6.25;
91 _ = .{ &a, &b, &c };
87 try expect(@mulAdd(f128, a, b, c) == 20);92 try expect(@mulAdd(f128, a, b, c) == 20);
88}93}
8994
...@@ -91,7 +96,8 @@ fn vector16() !void {...@@ -91,7 +96,8 @@ fn vector16() !void {
91 var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 };96 var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 };
92 var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 };97 var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 };
93 var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 };98 var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 };
94 var x = @mulAdd(@Vector(4, f16), a, b, c);99 _ = .{ &a, &b, &c };
100 const x = @mulAdd(@Vector(4, f16), a, b, c);
95101
96 try expect(x[0] == 20);102 try expect(x[0] == 20);
97 try expect(x[1] == 20);103 try expect(x[1] == 20);
...@@ -115,7 +121,8 @@ fn vector32() !void {...@@ -115,7 +121,8 @@ fn vector32() !void {
115 var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 };121 var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 };
116 var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 };122 var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 };
117 var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 };123 var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 };
118 var x = @mulAdd(@Vector(4, f32), a, b, c);124 _ = .{ &a, &b, &c };
125 const x = @mulAdd(@Vector(4, f32), a, b, c);
119126
120 try expect(x[0] == 20);127 try expect(x[0] == 20);
121 try expect(x[1] == 20);128 try expect(x[1] == 20);
...@@ -139,7 +146,8 @@ fn vector64() !void {...@@ -139,7 +146,8 @@ fn vector64() !void {
139 var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 };146 var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 };
140 var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 };147 var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 };
141 var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 };148 var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 };
142 var x = @mulAdd(@Vector(4, f64), a, b, c);149 _ = .{ &a, &b, &c };
150 const x = @mulAdd(@Vector(4, f64), a, b, c);
143151
144 try expect(x[0] == 20);152 try expect(x[0] == 20);
145 try expect(x[1] == 20);153 try expect(x[1] == 20);
...@@ -163,7 +171,8 @@ fn vector80() !void {...@@ -163,7 +171,8 @@ fn vector80() !void {
163 var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 };171 var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 };
164 var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 };172 var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 };
165 var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 };173 var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 };
166 var x = @mulAdd(@Vector(4, f80), a, b, c);174 _ = .{ &a, &b, &c };
175 const x = @mulAdd(@Vector(4, f80), a, b, c);
167 try expect(x[0] == 20);176 try expect(x[0] == 20);
168 try expect(x[1] == 20);177 try expect(x[1] == 20);
169 try expect(x[2] == 20);178 try expect(x[2] == 20);
...@@ -187,7 +196,8 @@ fn vector128() !void {...@@ -187,7 +196,8 @@ fn vector128() !void {
187 var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 };196 var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 };
188 var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 };197 var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 };
189 var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 };198 var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 };
190 var x = @mulAdd(@Vector(4, f128), a, b, c);199 _ = .{ &a, &b, &c };
200 const x = @mulAdd(@Vector(4, f128), a, b, c);
191201
192 try expect(x[0] == 20);202 try expect(x[0] == 20);
193 try expect(x[1] == 20);203 try expect(x[1] == 20);
test/behavior/null.zig+1
...@@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" {...@@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" {
134134
135 const EmptyStruct = struct {};135 const EmptyStruct = struct {};
136 var x: ?*EmptyStruct = null;136 var x: ?*EmptyStruct = null;
137 _ = &x;
137 try expect(x == null);138 try expect(x == null);
138}139}
139140
test/behavior/optional.zig+13-6
...@@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" {...@@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" {
1111
12 const S = struct {12 const S = struct {
13 fn entry() bool {13 fn entry() bool {
14 var x: i32 = 1234;14 const x: i32 = 1234;
15 return foo(x);15 return foo(x);
16 }16 }
1717
...@@ -29,7 +29,7 @@ test "optional pointer to size zero struct" {...@@ -29,7 +29,7 @@ test "optional pointer to size zero struct" {
29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3030
31 var e = EmptyStruct{};31 var e = EmptyStruct{};
32 var o: ?*EmptyStruct = &e;32 const o: ?*EmptyStruct = &e;
33 try expect(o != null);33 try expect(o != null);
34}34}
3535
...@@ -63,6 +63,7 @@ test "optional with void type" {...@@ -63,6 +63,7 @@ test "optional with void type" {
63 x: ?void,63 x: ?void,
64 };64 };
65 var x = Foo{ .x = null };65 var x = Foo{ .x = null };
66 _ = &x;
66 try expect(x.x == null);67 try expect(x.x == null);
67}68}
6869
...@@ -102,6 +103,7 @@ test "nested optional field in struct" {...@@ -102,6 +103,7 @@ test "nested optional field in struct" {
102 var s = S1{103 var s = S1{
103 .x = S2{ .y = 127 },104 .x = S2{ .y = 127 },
104 };105 };
106 _ = &s;
105 try expect(s.x.?.y == 127);107 try expect(s.x.?.y == 127);
106}108}
107109
...@@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void {...@@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void {
120 var five: i32 = 5;122 var five: i32 = 5;
121 var int_n: ?i32 = null;123 var int_n: ?i32 = null;
122124
125 _ = .{ &ten, &opt_ten, &five, &int_n };
126
123 try expect(int_n != ten);127 try expect(int_n != ten);
124 try expect(opt_ten == ten);128 try expect(opt_ten == ten);
125 try expect(opt_ten != five);129 try expect(opt_ten != five);
...@@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" {...@@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" {
208 };212 };
209 };213 };
210214
211 var n = S.Node.new();215 const n = S.Node.new();
212 try expect(n.data == null);216 try expect(n.data == null);
213}217}
214218
...@@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" {...@@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" {
252 const S = struct {256 const S = struct {
253 fn doTheTest() !void {257 fn doTheTest() !void {
254 var y = Foo{};258 var y = Foo{};
255 var z = y.thing();259 const z = y.thing();
256 try expect(z != null);260 try expect(z != null);
257 }261 }
258262
...@@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" {...@@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" {
425429
426 fn foo() ?I {430 fn foo() ?I {
427 var i: I = .{ .x = 1234 };431 var i: I = .{ .x = 1234 };
432 _ = &i;
428 return i;433 return i;
429 }434 }
430 };435 };
...@@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" {...@@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" {
450 const Thing = struct { n: i32 };455 const Thing = struct { n: i32 };
451 var a = false;456 var a = false;
452 var b = false;457 var b = false;
458 _ = .{ &a, &b };
453459
454 var result1 = if (a)460 const result1 = if (a)
455 Thing{ .n = 1 }461 Thing{ .n = 1 }
456 else462 else
457 null;463 null;
458 try expect(result1 == null);464 try expect(result1 == null);
459 try expect(@TypeOf(result1) == ?Thing);465 try expect(@TypeOf(result1) == ?Thing);
460466
461 var result2 = if (a)467 const result2 = if (a)
462 Thing{ .n = 0 }468 Thing{ .n = 0 }
463 else if (b)469 else if (b)
464 Thing{ .n = 1 }470 Thing{ .n = 1 }
...@@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" {...@@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" {
486492
487test "variable of optional of noreturn" {493test "variable of optional of noreturn" {
488 var null_opv: ?noreturn = null;494 var null_opv: ?noreturn = null;
495 _ = &null_opv;
489 try std.testing.expectEqual(@as(?noreturn, null), null_opv);496 try std.testing.expectEqual(@as(?noreturn, null), null_opv);
490}497}
test/behavior/packed-struct.zig+10-5
...@@ -479,10 +479,9 @@ test "load pointer from packed struct" {...@@ -479,10 +479,9 @@ test "load pointer from packed struct" {
479 y: u32,479 y: u32,
480 };480 };
481 var a: A = .{ .index = 123 };481 var a: A = .{ .index = 123 };
482 var b_list: []const B = &.{.{ .x = &a, .y = 99 }};482 const b_list: []const B = &.{.{ .x = &a, .y = 99 }};
483 for (b_list) |b| {483 for (b_list) |b| {
484 var i = b.x.index;484 try expect(b.x.index == 123);
485 try expect(i == 123);
486 }485 }
487}486}
488487
...@@ -770,6 +769,7 @@ test "nested packed struct field access test" {...@@ -770,6 +769,7 @@ test "nested packed struct field access test" {
770 };769 };
771770
772 var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } };771 var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } };
772 _ = &arg;
773 try std.testing.expect(arg.b.c == 1);773 try std.testing.expect(arg.b.c == 1);
774 try std.testing.expect(arg.b.d == 2);774 try std.testing.expect(arg.b.d == 2);
775 try std.testing.expect(arg.g.h == 6);775 try std.testing.expect(arg.g.h == 6);
...@@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" {...@@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" {
790 };790 };
791791
792 var k: u8 = 123;792 var k: u8 = 123;
793 _ = &k;
793 var v: A = .{794 var v: A = .{
794 .p1 = .{ .a = k + 1, .b = k },795 .p1 = .{ .a = k + 1, .b = k },
795 .p2 = .{ .a = k + 1, .b = k },796 .p2 = .{ .a = k + 1, .b = k },
...@@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" {...@@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" {
833834
834 fn doTheTest() !void {835 fn doTheTest() !void {
835 var k: u8 = 123;836 var k: u8 = 123;
837 _ = &k;
836 var v: A = .{838 var v: A = .{
837 .p1 = .{ .a = k + 1, .b = k },839 .p1 = .{ .a = k + 1, .b = k },
838 .p2 = .{ .a = k + 1, .b = k },840 .p2 = .{ .a = k + 1, .b = k },
...@@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" {...@@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" {
877 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;879 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
878880
879 var z: u8 = 123;881 var z: u8 = 123;
882 _ = &z;
880 try (packed struct {883 try (packed struct {
881 x: u8,884 x: u8,
882 pub fn m(s: @This()) !void {885 pub fn m(s: @This()) !void {
...@@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" {...@@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" {
941944
942 const T = packed struct { val: u8 };945 const T = packed struct { val: u8 };
943 var val: u8 = 123;946 var val: u8 = 123;
947 _ = &val;
944 const t = @as(u8, @bitCast(T{ .val = val }));948 const t = @as(u8, @bitCast(T{ .val = val }));
945 try expect(t == val);949 try expect(t == val);
946}950}
...@@ -976,7 +980,8 @@ test "store undefined to packed result location" {...@@ -976,7 +980,8 @@ test "store undefined to packed result location" {
976 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;980 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
977981
978 var x: u4 = 0;982 var x: u4 = 0;
979 var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };983 _ = &x;
984 const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };
980 try expectEqual(x, s.x);985 try expectEqual(x, s.x);
981}986}
982987
...@@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init...@@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init
1004 }1009 }
1005 };1010 };
10061011
1007 var s = S.init(true);1012 const s = S.init(true);
1008 // note: this bug is triggered by the == operator, expectEqual will hide it1013 // note: this bug is triggered by the == operator, expectEqual will hide it
1009 try expect(@as(i2, 0) == s.ps.x);1014 try expect(@as(i2, 0) == s.ps.x);
1010 try expect(@as(i2, 1) == s.ps.y);1015 try expect(@as(i2, 1) == s.ps.y);
test/behavior/pointers.zig+37-23
...@@ -11,7 +11,7 @@ test "dereference pointer" {...@@ -11,7 +11,7 @@ test "dereference pointer" {
1111
12fn testDerefPtr() !void {12fn testDerefPtr() !void {
13 var x: i32 = 1234;13 var x: i32 = 1234;
14 var y = &x;14 const y = &x;
15 y.* += 1;15 y.* += 1;
16 try expect(x == 1235);16 try expect(x == 1235);
17}17}
...@@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" {...@@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" {
53 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO53 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
5454
55 var y: u8 = 11;55 var y: u8 = 11;
56 var x: [*c]u8 = &y;56 const x: [*c]u8 = &y;
57 var z: *u8 = x;57 const z: *u8 = x;
58 z.* += 1;58 z.* += 1;
59 try expect(y == 12);59 try expect(y == 12);
60}60}
...@@ -74,6 +74,7 @@ test "assigning integer to C pointer" {...@@ -74,6 +74,7 @@ test "assigning integer to C pointer" {
74 var ptr2: [*c]u8 = x;74 var ptr2: [*c]u8 = x;
75 var ptr3: [*c]u8 = 1;75 var ptr3: [*c]u8 = 1;
76 var ptr4: [*c]u8 = y;76 var ptr4: [*c]u8 = y;
77 _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 };
7778
78 try expect(ptr == ptr2);79 try expect(ptr == ptr2);
79 try expect(ptr3 == ptr4);80 try expect(ptr3 == ptr4);
...@@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" {...@@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" {
88 fn doTheTest() !void {89 fn doTheTest() !void {
89 var ptr1: [*c]u32 = 0;90 var ptr1: [*c]u32 = 0;
90 var ptr2 = ptr1 + 10;91 var ptr2 = ptr1 + 10;
92 _ = &ptr1;
91 try expect(ptr1 == 0);93 try expect(ptr1 == 0);
92 try expect(ptr1 >= 0);94 try expect(ptr1 >= 0);
93 try expect(ptr1 <= 0);95 try expect(ptr1 <= 0);
...@@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void {...@@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void {
125}127}
126128
127test "peer type resolution with C pointers" {129test "peer type resolution with C pointers" {
128 var ptr_one: *u8 = undefined;130 const ptr_one: *u8 = undefined;
129 var ptr_many: [*]u8 = undefined;131 const ptr_many: [*]u8 = undefined;
130 var ptr_c: [*c]u8 = undefined;132 const ptr_c: [*c]u8 = undefined;
131 var t = true;133 var t = true;
132 var x1 = if (t) ptr_one else ptr_c;134 _ = &t;
133 var x2 = if (t) ptr_many else ptr_c;135 const x1 = if (t) ptr_one else ptr_c;
134 var x3 = if (t) ptr_c else ptr_one;136 const x2 = if (t) ptr_many else ptr_c;
135 var x4 = if (t) ptr_c else ptr_many;137 const x3 = if (t) ptr_c else ptr_one;
138 const x4 = if (t) ptr_c else ptr_many;
136 try expect(@TypeOf(x1) == [*c]u8);139 try expect(@TypeOf(x1) == [*c]u8);
137 try expect(@TypeOf(x2) == [*c]u8);140 try expect(@TypeOf(x2) == [*c]u8);
138 try expect(@TypeOf(x3) == [*c]u8);141 try expect(@TypeOf(x3) == [*c]u8);
...@@ -141,8 +144,9 @@ test "peer type resolution with C pointers" {...@@ -141,8 +144,9 @@ test "peer type resolution with C pointers" {
141144
142test "peer type resolution with C pointer and const pointer" {145test "peer type resolution with C pointer and const pointer" {
143 var ptr_c: [*c]u8 = undefined;146 var ptr_c: [*c]u8 = undefined;
144 const ptr_const: u8 = undefined;147 var ptr_const: *const u8 = &undefined;
145 try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8);148 _ = .{ &ptr_c, &ptr_const };
149 try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8);
146}150}
147151
148test "implicit casting between C pointer and optional non-C pointer" {152test "implicit casting between C pointer and optional non-C pointer" {
...@@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" {...@@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" {
151 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO155 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
152156
153 var slice: []const u8 = "aoeu";157 var slice: []const u8 = "aoeu";
158 _ = &slice;
154 const opt_many_ptr: ?[*]const u8 = slice.ptr;159 const opt_many_ptr: ?[*]const u8 = slice.ptr;
155 var ptr_opt_many_ptr = &opt_many_ptr;160 var ptr_opt_many_ptr = &opt_many_ptr;
156 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;161 const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
157 try expect(c_ptr.*.* == 'a');162 try expect(c_ptr.*.* == 'a');
158 ptr_opt_many_ptr = c_ptr;163 ptr_opt_many_ptr = c_ptr;
159 try expect(ptr_opt_many_ptr.*.?[1] == 'o');164 try expect(ptr_opt_many_ptr.*.?[1] == 'o');
...@@ -192,11 +197,12 @@ test "allowzero pointer and slice" {...@@ -192,11 +197,12 @@ test "allowzero pointer and slice" {
192 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;197 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
193 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO198 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
194199
195 var ptr = @as([*]allowzero i32, @ptrFromInt(0));200 var ptr: [*]allowzero i32 = @ptrFromInt(0);
196 var opt_ptr: ?[*]allowzero i32 = ptr;201 const opt_ptr: ?[*]allowzero i32 = ptr;
197 try expect(opt_ptr != null);202 try expect(opt_ptr != null);
198 try expect(@intFromPtr(ptr) == 0);203 try expect(@intFromPtr(ptr) == 0);
199 var runtime_zero: usize = 0;204 var runtime_zero: usize = 0;
205 _ = &runtime_zero;
200 var slice = ptr[runtime_zero..10];206 var slice = ptr[runtime_zero..10];
201 try comptime expect(@TypeOf(slice) == []allowzero i32);207 try comptime expect(@TypeOf(slice) == []allowzero i32);
202 try expect(@intFromPtr(&slice[5]) == 20);208 try expect(@intFromPtr(&slice[5]) == 20);
...@@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" {...@@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" {
211 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO217 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
212218
213 var x: [*c]i32 = null;219 var x: [*c]i32 = null;
220 _ = &x;
214 try expect(x == null);221 try expect(x == null);
215 try expect(null == x);222 try expect(null == x);
216 try expect(!(x != null));223 try expect(!(x != null));
...@@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" {...@@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" {
236 try comptime expect((y orelse ptr_othery) == ptr_othery);243 try comptime expect((y orelse ptr_othery) == ptr_othery);
237244
238 var n: i32 = 1234;245 var n: i32 = 1234;
239 var x1: [*c]i32 = &n;246 const x1: [*c]i32 = &n;
240 try expect(!(x1 == null));247 try expect(!(x1 == null));
241 try expect(!(null == x1));248 try expect(!(null == x1));
242 try expect(x1 != null);249 try expect(x1 != null);
...@@ -279,9 +286,9 @@ test "null terminated pointer" {...@@ -279,9 +286,9 @@ test "null terminated pointer" {
279 const S = struct {286 const S = struct {
280 fn doTheTest() !void {287 fn doTheTest() !void {
281 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };288 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
282 var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero));289 const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero);
283 var no_zero_ptr: [*]const u8 = zero_ptr;290 const no_zero_ptr: [*]const u8 = zero_ptr;
284 var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr));291 const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr);
285 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));292 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));
286 }293 }
287 };294 };
...@@ -296,7 +303,7 @@ test "allow any sentinel" {...@@ -296,7 +303,7 @@ test "allow any sentinel" {
296 const S = struct {303 const S = struct {
297 fn doTheTest() !void {304 fn doTheTest() !void {
298 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };305 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
299 var ptr: [*:std.math.minInt(i32)]i32 = &array;306 const ptr: [*:std.math.minInt(i32)]i32 = &array;
300 try expect(ptr[4] == std.math.minInt(i32));307 try expect(ptr[4] == std.math.minInt(i32));
301 }308 }
302 };309 };
...@@ -317,6 +324,7 @@ test "pointer sentinel with enums" {...@@ -317,6 +324,7 @@ test "pointer sentinel with enums" {
317324
318 fn doTheTest() !void {325 fn doTheTest() !void {
319 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };326 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
327 _ = &ptr;
320 try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731328 try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731
321 }329 }
322 };330 };
...@@ -332,6 +340,7 @@ test "pointer sentinel with optional element" {...@@ -332,6 +340,7 @@ test "pointer sentinel with optional element" {
332 const S = struct {340 const S = struct {
333 fn doTheTest() !void {341 fn doTheTest() !void {
334 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };342 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
343 _ = &ptr;
335 try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731344 try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731
336 }345 }
337 };346 };
...@@ -348,6 +357,7 @@ test "pointer sentinel with +inf" {...@@ -348,6 +357,7 @@ test "pointer sentinel with +inf" {
348 fn doTheTest() !void {357 fn doTheTest() !void {
349 const inf_f32 = comptime std.math.inf(f32);358 const inf_f32 = comptime std.math.inf(f32);
350 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };359 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };
360 _ = &ptr;
351 try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731361 try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731
352 }362 }
353 };363 };
...@@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" {...@@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" {
366 {376 {
367 var ptr: [*]align(8) u32 = undefined;377 var ptr: [*]align(8) u32 = undefined;
368 var x: usize = 1;378 var x: usize = 1;
379 _ = .{ &ptr, &x };
369380
370 try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);381 try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
371 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4382 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4
...@@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" {...@@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" {
380 {391 {
381 var ptr: [*]align(8) [3]u8 = undefined;392 var ptr: [*]align(8) [3]u8 = undefined;
382 var x: usize = 1;393 var x: usize = 1;
394 _ = .{ &ptr, &x };
383395
384 const ptr1 = ptr + 17; // 3 * 17 = 51396 const ptr1 = ptr + 17; // 3 * 17 = 51
385 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);397 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
...@@ -467,8 +479,8 @@ test "array slicing to slice" {...@@ -467,8 +479,8 @@ test "array slicing to slice" {
467 const S = struct {479 const S = struct {
468 fn doTheTest() !void {480 fn doTheTest() !void {
469 var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 };481 var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 };
470 var sub: *[2]i32 = str[1..3];482 const sub: *[2]i32 = str[1..3];
471 var slice: []i32 = sub; // used to cause failures483 const slice: []i32 = sub; // used to cause failures
472 try testing.expect(slice.len == 2);484 try testing.expect(slice.len == 2);
473 try testing.expect(slice[0] == 2);485 try testing.expect(slice[0] == 2);
474 }486 }
...@@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" {...@@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" {
495 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO507 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
496508
497 const s: [:0]const u8 = "foo";509 const s: [:0]const u8 = "foo";
498 var p = @as([*c]const u8, @ptrCast(s));510 var p: [*c]const u8 = @ptrCast(s);
511 _ = &p;
499 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));512 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));
500}513}
501514
...@@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" {...@@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" {
527test "result type preserved through multiple references" {540test "result type preserved through multiple references" {
528 const S = struct { x: u32 };541 const S = struct { x: u32 };
529 var my_u64: u64 = 12345;542 var my_u64: u64 = 12345;
543 _ = &my_u64;
530 const foo: *const *const *const S = &&&.{544 const foo: *const *const *const S = &&&.{
531 .x = @intCast(my_u64),545 .x = @intCast(my_u64),
532 };546 };
test/behavior/popcount.zig+10
...@@ -26,6 +26,7 @@ test "@popCount 128bit integer" {...@@ -26,6 +26,7 @@ test "@popCount 128bit integer" {
2626
27 {27 {
28 var x: u128 = 0b11111111000110001100010000100001000011000011100101010001;28 var x: u128 = 0b11111111000110001100010000100001000011000011100101010001;
29 _ = &x;
29 try expect(@popCount(x) == 24);30 try expect(@popCount(x) == 24);
30 }31 }
3132
...@@ -35,30 +36,37 @@ test "@popCount 128bit integer" {...@@ -35,30 +36,37 @@ test "@popCount 128bit integer" {
35fn testPopCountIntegers() !void {36fn testPopCountIntegers() !void {
36 {37 {
37 var x: u32 = 0xffffffff;38 var x: u32 = 0xffffffff;
39 _ = &x;
38 try expect(@popCount(x) == 32);40 try expect(@popCount(x) == 32);
39 }41 }
40 {42 {
41 var x: u5 = 0x1f;43 var x: u5 = 0x1f;
44 _ = &x;
42 try expect(@popCount(x) == 5);45 try expect(@popCount(x) == 5);
43 }46 }
44 {47 {
45 var x: u32 = 0xaa;48 var x: u32 = 0xaa;
49 _ = &x;
46 try expect(@popCount(x) == 4);50 try expect(@popCount(x) == 4);
47 }51 }
48 {52 {
49 var x: u32 = 0xaaaaaaaa;53 var x: u32 = 0xaaaaaaaa;
54 _ = &x;
50 try expect(@popCount(x) == 16);55 try expect(@popCount(x) == 16);
51 }56 }
52 {57 {
53 var x: u32 = 0xaaaaaaaa;58 var x: u32 = 0xaaaaaaaa;
59 _ = &x;
54 try expect(@popCount(x) == 16);60 try expect(@popCount(x) == 16);
55 }61 }
56 {62 {
57 var x: i16 = -1;63 var x: i16 = -1;
64 _ = &x;
58 try expect(@popCount(x) == 16);65 try expect(@popCount(x) == 16);
59 }66 }
60 {67 {
61 var x: i8 = -120;68 var x: i8 = -120;
69 _ = &x;
62 try expect(@popCount(x) == 2);70 try expect(@popCount(x) == 2);
63 }71 }
64 comptime {72 comptime {
...@@ -81,12 +89,14 @@ test "@popCount vectors" {...@@ -81,12 +89,14 @@ test "@popCount vectors" {
81fn testPopCountVectors() !void {89fn testPopCountVectors() !void {
82 {90 {
83 var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8;91 var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8;
92 _ = &x;
84 const expected = [1]u6{32} ** 8;93 const expected = [1]u6{32} ** 8;
85 const result: [8]u6 = @popCount(x);94 const result: [8]u6 = @popCount(x);
86 try expect(std.mem.eql(u6, &expected, &result));95 try expect(std.mem.eql(u6, &expected, &result));
87 }96 }
88 {97 {
89 var x: @Vector(8, i16) = [1]i16{-1} ** 8;98 var x: @Vector(8, i16) = [1]i16{-1} ** 8;
99 _ = &x;
90 const expected = [1]u5{16} ** 8;100 const expected = [1]u5{16} ** 8;
91 const result: [8]u5 = @popCount(x);101 const result: [8]u5 = @popCount(x);
92 try expect(std.mem.eql(u5, &expected, &result));102 try expect(std.mem.eql(u5, &expected, &result));
test/behavior/prefetch.zig+1
...@@ -6,6 +6,7 @@ test "@prefetch()" {...@@ -6,6 +6,7 @@ test "@prefetch()" {
66
7 var a: [2]u32 = .{ 42, 42 };7 var a: [2]u32 = .{ 42, 42 };
8 var a_len = a.len;8 var a_len = a.len;
9 _ = &a_len;
910
10 @prefetch(&a, .{});11 @prefetch(&a, .{});
1112
test/behavior/ptrcast.zig+14-14
...@@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void {...@@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void {
71 c: u8,71 c: u8,
72 };72 };
7373
74 var ptr = @as(*const S, @ptrCast(&bytes));74 const ptr: *const S = @ptrCast(&bytes);
75 var val = ptr.c;75 const val = ptr.c;
76 try expect(val == 5);76 try expect(val == 5);
77}77}
7878
...@@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void {...@@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void {
95 a: u32 align(2),95 a: u32 align(2),
96 c: u8,96 c: u8,
97 };97 };
98 var ptr = @as(*const S2, @ptrCast(&bytes));98 const ptr: *const S2 = @ptrCast(&bytes);
99 var val = ptr.c;99 const val = ptr.c;
100 try expect(val == 5);100 try expect(val == 5);
101}101}
102102
...@@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {...@@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
121 a2: u16,121 a2: u16,
122 c: u8,122 c: u8,
123 };123 };
124 var ptr = @as(*const S2, @ptrCast(&bytes));124 const ptr: *const S2 = @ptrCast(&bytes);
125 var val = ptr.c;125 const val = ptr.c;
126 try expect(val == 5);126 try expect(val == 5);
127}127}
128128
...@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {...@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
138 c: u8,138 c: u8,
139 };139 };
140 comptime var ptr = @as(*const S, @ptrCast(&bytes));140 comptime var ptr = @as(*const S, @ptrCast(&bytes));
141 var val = &ptr.c;141 const val = &ptr.c;
142 try expect(val.* == 5);142 try expect(val.* == 5);
143143
144 // Test lowering an elem ptr144 // Test lowering an elem ptr
145 comptime var src_value = S{ .a = 15, .c = 5 };145 comptime var src_value = S{ .a = 15, .c = 5 };
146 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));146 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
147 var val2 = &ptr2[4];147 const val2 = &ptr2[4];
148 try expect(val2.* == 5);148 try expect(val2.* == 5);
149}149}
150150
...@@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" {...@@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" {
160 c: u8,160 c: u8,
161 };161 };
162 comptime var ptr = @as(*const S, @ptrCast(&bytes));162 comptime var ptr = @as(*const S, @ptrCast(&bytes));
163 var val = &ptr.c;163 const val = &ptr.c;
164 try expect(val.* == 5);164 try expect(val.* == 5);
165165
166 // Test lowering an elem ptr166 // Test lowering an elem ptr
167 comptime var src_value = S{ .a = 15, .c = 5 };167 comptime var src_value = S{ .a = 15, .c = 5 };
168 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));168 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
169 var val2 = &ptr2[4];169 const val2 = &ptr2[4];
170 try expect(val2.* == 5);170 try expect(val2.* == 5);
171}171}
172172
...@@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" {...@@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" {
233 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO233 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
234234
235 var buf: [4]u8 = "aoeu".*;235 var buf: [4]u8 = "aoeu".*;
236 var x: ?[*]u8 = &buf;236 const x: ?[*]u8 = &buf;
237 var y: ?*anyopaque = x;237 const y: ?*anyopaque = x;
238 var z = @as(*[4]u8, @ptrCast(y));238 const z: *[4]u8 = @ptrCast(y);
239 try expect(std.mem.eql(u8, z, "aoeu"));239 try expect(std.mem.eql(u8, z, "aoeu"));
240}240}
241241
...@@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" {...@@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" {
276 }276 }
277 };277 };
278 comptime {278 comptime {
279 var x = S.transmute([]u8, i32, undefined);279 const x = S.transmute([]u8, i32, undefined);
280 _ = x;280 _ = x;
281 }281 }
282}282}
test/behavior/ptrfromint.zig+1
...@@ -9,6 +9,7 @@ test "casting integer address to function pointer" {...@@ -9,6 +9,7 @@ test "casting integer address to function pointer" {
99
10fn addressToFunction() void {10fn addressToFunction() void {
11 var addr: usize = 0xdeadbee0;11 var addr: usize = 0xdeadbee0;
12 _ = &addr;
12 _ = @as(*const fn () void, @ptrFromInt(addr));13 _ = @as(*const fn () void, @ptrFromInt(addr));
13}14}
1415
test/behavior/saturating_arithmetic.zig+2
...@@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" {...@@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" {
246246
247 const lhs_const: u8 = 1;247 const lhs_const: u8 = 1;
248 var lhs_var: u8 = 1;248 var lhs_var: u8 = 1;
249 _ = &lhs_var;
249250
250 const rhs_const: usize = 8;251 const rhs_const: usize = 8;
251 var rhs_var: usize = 8;252 var rhs_var: usize = 8;
253 _ = &rhs_var;
252254
253 try expect((lhs_const <<| 8) == 255);255 try expect((lhs_const <<| 8) == 255);
254 try expect((lhs_const <<| rhs_const) == 255);256 try expect((lhs_const <<| rhs_const) == 255);
test/behavior/select.zig+8-4
...@@ -19,7 +19,8 @@ fn selectVectors() !void {...@@ -19,7 +19,8 @@ fn selectVectors() !void {
19 var a = @Vector(4, bool){ true, false, true, false };19 var a = @Vector(4, bool){ true, false, true, false };
20 var b = @Vector(4, i32){ -1, 4, 999, -31 };20 var b = @Vector(4, i32){ -1, 4, 999, -31 };
21 var c = @Vector(4, i32){ -5, 1, 0, 1234 };21 var c = @Vector(4, i32){ -5, 1, 0, 1234 };
22 var abc = @select(i32, a, b, c);22 _ = .{ &a, &b, &c };
23 const abc = @select(i32, a, b, c);
23 try expect(abc[0] == -1);24 try expect(abc[0] == -1);
24 try expect(abc[1] == 1);25 try expect(abc[1] == 1);
25 try expect(abc[2] == 999);26 try expect(abc[2] == 999);
...@@ -28,7 +29,8 @@ fn selectVectors() !void {...@@ -28,7 +29,8 @@ fn selectVectors() !void {
28 var x = @Vector(4, bool){ false, false, false, true };29 var x = @Vector(4, bool){ false, false, false, true };
29 var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 };30 var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 };
30 var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 };31 var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 };
31 var xyz = @select(f32, x, y, z);32 _ = .{ &x, &y, &z };
33 const xyz = @select(f32, x, y, z);
32 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));34 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));
33}35}
3436
...@@ -48,7 +50,8 @@ fn selectArrays() !void {...@@ -48,7 +50,8 @@ fn selectArrays() !void {
48 var a = [4]bool{ false, true, false, true };50 var a = [4]bool{ false, true, false, true };
49 var b = [4]usize{ 0, 1, 2, 3 };51 var b = [4]usize{ 0, 1, 2, 3 };
50 var c = [4]usize{ 4, 5, 6, 7 };52 var c = [4]usize{ 4, 5, 6, 7 };
51 var abc = @select(usize, a, b, c);53 _ = .{ &a, &b, &c };
54 const abc = @select(usize, a, b, c);
52 try expect(abc[0] == 4);55 try expect(abc[0] == 4);
53 try expect(abc[1] == 1);56 try expect(abc[1] == 1);
54 try expect(abc[2] == 6);57 try expect(abc[2] == 6);
...@@ -57,6 +60,7 @@ fn selectArrays() !void {...@@ -57,6 +60,7 @@ fn selectArrays() !void {
57 var x = [4]bool{ false, false, false, true };60 var x = [4]bool{ false, false, false, true };
58 var y = [4]f32{ 0.001, 33.4, 836, -3381.233 };61 var y = [4]f32{ 0.001, 33.4, 836, -3381.233 };
59 var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 };62 var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 };
60 var xyz = @select(f32, x, y, z);63 _ = .{ &x, &y, &z };
64 const xyz = @select(f32, x, y, z);
61 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));65 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));
62}66}
test/behavior/shuffle.zig+10-2
...@@ -13,7 +13,9 @@ test "@shuffle int" {...@@ -13,7 +13,9 @@ test "@shuffle int" {
13 const S = struct {13 const S = struct {
14 fn doTheTest() !void {14 fn doTheTest() !void {
15 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };15 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
16 _ = &v;
16 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };17 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
18 _ = &x;
17 const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };19 const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
18 var res = @shuffle(i32, v, x, mask);20 var res = @shuffle(i32, v, x, mask);
19 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));21 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
...@@ -29,12 +31,14 @@ test "@shuffle int" {...@@ -29,12 +31,14 @@ test "@shuffle int" {
2931
30 // Upcasting of b32 // Upcasting of b
31 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };33 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
34 _ = &v2;
32 const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };35 const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
33 res = @shuffle(i32, x, v2, mask3);36 res = @shuffle(i32, x, v2, mask3);
34 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));37 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
3538
36 // Upcasting of a39 // Upcasting of a
37 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };40 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
41 _ = &v3;
38 const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };42 const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
39 res = @shuffle(i32, v3, x, mask4);43 res = @shuffle(i32, v3, x, mask4);
40 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));44 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
...@@ -55,9 +59,11 @@ test "@shuffle bool 1" {...@@ -55,9 +59,11 @@ test "@shuffle bool 1" {
55 const S = struct {59 const S = struct {
56 fn doTheTest() !void {60 fn doTheTest() !void {
57 var x: @Vector(4, bool) = [4]bool{ false, true, false, true };61 var x: @Vector(4, bool) = [4]bool{ false, true, false, true };
62 _ = &x;
58 var v: @Vector(2, bool) = [2]bool{ true, false };63 var v: @Vector(2, bool) = [2]bool{ true, false };
64 _ = &v;
59 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };65 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
60 var res = @shuffle(bool, x, v, mask);66 const res = @shuffle(bool, x, v, mask);
61 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));67 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));
62 }68 }
63 };69 };
...@@ -81,9 +87,11 @@ test "@shuffle bool 2" {...@@ -81,9 +87,11 @@ test "@shuffle bool 2" {
81 const S = struct {87 const S = struct {
82 fn doTheTest() !void {88 fn doTheTest() !void {
83 var x: @Vector(3, bool) = [3]bool{ false, true, false };89 var x: @Vector(3, bool) = [3]bool{ false, true, false };
90 _ = &x;
84 var v: @Vector(2, bool) = [2]bool{ true, false };91 var v: @Vector(2, bool) = [2]bool{ true, false };
92 _ = &v;
85 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };93 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
86 var res = @shuffle(bool, x, v, mask);94 const res = @shuffle(bool, x, v, mask);
87 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));95 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));
88 }96 }
89 };97 };
test/behavior/sizeof_and_typeof.zig+6
...@@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" {...@@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" {
22 var var_1: u32 = undefined;22 var var_1: u32 = undefined;
23 var var_2: u8 = undefined;23 var var_2: u8 = undefined;
24 var var_3: u64 = undefined;24 var var_3: u64 = undefined;
25 _ = .{ &var_1, &var_2, &var_3 };
25 try comptime expect(@TypeOf(var_1, var_2, var_3) == u64);26 try comptime expect(@TypeOf(var_1, var_2, var_3) == u64);
26 }27 }
27 {28 {
28 var var_1: f16 = undefined;29 var var_1: f16 = undefined;
29 var var_2: f32 = undefined;30 var var_2: f32 = undefined;
30 var var_3: f64 = undefined;31 var var_3: f64 = undefined;
32 _ = .{ &var_1, &var_2, &var_3 };
31 try comptime expect(@TypeOf(var_1, var_2, var_3) == f64);33 try comptime expect(@TypeOf(var_1, var_2, var_3) == f64);
32 }34 }
33 {35 {
34 var var_1: u16 = undefined;36 var var_1: u16 = undefined;
37 _ = &var_1;
35 try comptime expect(@TypeOf(var_1, 0xffff) == u16);38 try comptime expect(@TypeOf(var_1, 0xffff) == u16);
36 }39 }
37 {40 {
38 var var_1: f32 = undefined;41 var var_1: f32 = undefined;
42 _ = &var_1;
39 try comptime expect(@TypeOf(var_1, 3.1415) == f32);43 try comptime expect(@TypeOf(var_1, 3.1415) == f32);
40 }44 }
41}45}
...@@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" {...@@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" {
269273
270 {274 {
271 var y: i8 = 2;275 var y: i8 = 2;
276 _ = &y;
272 const i: [2]i8 = [_]i8{ 1, y };277 const i: [2]i8 = [_]i8{ 1, y };
273 const T = struct {278 const T = struct {
274 a: @TypeOf(i) = undefined, // causes crash279 a: @TypeOf(i) = undefined, // causes crash
...@@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" {...@@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" {
279 }284 }
280 {285 {
281 var y: i8 = 2;286 var y: i8 = 2;
287 _ = &y;
282 const i = .{ 1, y };288 const i = .{ 1, y };
283 const T = struct {289 const T = struct {
284 b: @TypeOf(i[1]) = undefined,290 b: @TypeOf(i[1]) = undefined,
test/behavior/slice.zig+44-32
...@@ -23,7 +23,7 @@ comptime {...@@ -23,7 +23,7 @@ comptime {
23 };23 };
24 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };24 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
25 const list: []const type = &unsigned;25 const list: []const type = &unsigned;
26 var pos = S.indexOfScalar(type, list, c_ulong).?;26 const pos = S.indexOfScalar(type, list, c_ulong).?;
27 if (pos != 1) @compileError("bad pos");27 if (pos != 1) @compileError("bad pos");
28}28}
2929
...@@ -36,13 +36,14 @@ test "slicing" {...@@ -36,13 +36,14 @@ test "slicing" {
3636
37 var slice = array[5..10];37 var slice = array[5..10];
3838
39 if (slice.len != 5) unreachable;39 try expect(slice.len == 5);
4040
41 const ptr = &slice[0];41 const ptr = &slice[0];
42 if (ptr.* != 1234) unreachable;42 try expect(ptr.* == 1234);
4343
44 var slice_rest = array[10..];44 var slice_rest = array[10..];
45 if (slice_rest.len != 10) unreachable;45 _ = &slice_rest;
46 try expect(slice_rest.len == 10);
46}47}
4748
48test "const slice" {49test "const slice" {
...@@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" {...@@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" {
79 const S = struct {80 const S = struct {
80 fn doTheTest() !void {81 fn doTheTest() !void {
81 var slice: [:0]const u8 = "hello";82 var slice: [:0]const u8 = "hello";
8283 _ = &slice;
83 try expect(slice.len == 5);84 try expect(slice.len == 5);
84 try expect(slice[5] == 0);85 try expect(slice[5] == 0);
85 }86 }
...@@ -208,6 +209,7 @@ test "slice string literal has correct type" {...@@ -208,6 +209,7 @@ test "slice string literal has correct type" {
208 try expect(@TypeOf(array[0..]) == *const [4]i32);209 try expect(@TypeOf(array[0..]) == *const [4]i32);
209 }210 }
210 var runtime_zero: usize = 0;211 var runtime_zero: usize = 0;
212 _ = &runtime_zero;
211 try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);213 try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
212 const array = [_]i32{ 1, 2, 3, 4 };214 const array = [_]i32{ 1, 2, 3, 4 };
213 try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);215 try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);
...@@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic...@@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic
219 const E = struct {221 const E = struct {
220 entries: []u32,222 entries: []u32,
221 };223 };
222 var foo = E{ .entries = &[_]u32{} };224 var foo: E = .{ .entries = &[_]u32{} };
225 _ = &foo;
223 try expect(foo.entries.len == 0);226 try expect(foo.entries.len == 0);
224}227}
225228
...@@ -242,7 +245,8 @@ test "C pointer" {...@@ -242,7 +245,8 @@ test "C pointer" {
242245
243 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";246 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
244 var len: u32 = 10;247 var len: u32 = 10;
245 var slice = buf[0..len];248 _ = &len;
249 const slice = buf[0..len];
246 try expect(mem.eql(u8, "kjdhfkjdhf", slice));250 try expect(mem.eql(u8, "kjdhfkjdhf", slice));
247}251}
248252
...@@ -255,6 +259,7 @@ test "C pointer slice access" {...@@ -255,6 +259,7 @@ test "C pointer slice access" {
255 const c_ptr = @as([*c]const u32, @ptrCast(&buf));259 const c_ptr = @as([*c]const u32, @ptrCast(&buf));
256260
257 var runtime_zero: usize = 0;261 var runtime_zero: usize = 0;
262 _ = &runtime_zero;
258 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));263 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
259 try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));264 try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
260265
...@@ -306,11 +311,13 @@ test "obtaining a null terminated slice" {...@@ -306,11 +311,13 @@ test "obtaining a null terminated slice" {
306 _ = ptr;311 _ = ptr;
307312
308 var runtime_len: usize = 3;313 var runtime_len: usize = 3;
314 _ = &runtime_len;
309 const ptr2 = buf[0..runtime_len :0];315 const ptr2 = buf[0..runtime_len :0];
310 // ptr2 is a null-terminated slice316 // ptr2 is a null-terminated slice
311 try comptime expect(@TypeOf(ptr2) == [:0]u8);317 try comptime expect(@TypeOf(ptr2) == [:0]u8);
312 try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);318 try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);
313 var runtime_zero: usize = 0;319 var runtime_zero: usize = 0;
320 _ = &runtime_zero;
314 try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);321 try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
315}322}
316323
...@@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" {...@@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" {
338 const S = struct {345 const S = struct {
339 fn doTheTest() !void {346 fn doTheTest() !void {
340 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };347 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
341 var slice: []align(@alignOf(u16)) u8 = &array;348 const slice: []align(@alignOf(u16)) u8 = &array;
342 var ptr = @as(*u16, @ptrCast(slice));349 const ptr: *u16 = @ptrCast(slice);
343 try expect(ptr.* == 65535);350 try expect(ptr.* == 65535);
344 }351 }
345 };352 };
...@@ -357,8 +364,8 @@ test "slice multi-pointer without end" {...@@ -357,8 +364,8 @@ test "slice multi-pointer without end" {
357364
358 fn testPointer() !void {365 fn testPointer() !void {
359 var array = [5]u8{ 1, 2, 3, 4, 5 };366 var array = [5]u8{ 1, 2, 3, 4, 5 };
360 var pointer: [*]u8 = &array;367 const pointer: [*]u8 = &array;
361 var slice = pointer[1..];368 const slice = pointer[1..];
362 try comptime expect(@TypeOf(slice) == [*]u8);369 try comptime expect(@TypeOf(slice) == [*]u8);
363 try expect(slice[0] == 2);370 try expect(slice[0] == 2);
364 try expect(slice[1] == 3);371 try expect(slice[1] == 3);
...@@ -366,13 +373,13 @@ test "slice multi-pointer without end" {...@@ -366,13 +373,13 @@ test "slice multi-pointer without end" {
366373
367 fn testPointerZ() !void {374 fn testPointerZ() !void {
368 var array = [5:0]u8{ 1, 2, 3, 4, 5 };375 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
369 var pointer: [*:0]u8 = &array;376 const pointer: [*:0]u8 = &array;
370377
371 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);378 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
372 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);379 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
373 try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);380 try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);
374381
375 var slice = pointer[1..];382 const slice = pointer[1..];
376 try comptime expect(@TypeOf(slice) == [*:0]u8);383 try comptime expect(@TypeOf(slice) == [*:0]u8);
377 try expect(slice[0] == 2);384 try expect(slice[0] == 2);
378 try expect(slice[1] == 3);385 try expect(slice[1] == 3);
...@@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" {
413420
414 fn testArray() !void {421 fn testArray() !void {
415 var array = [5]u8{ 1, 2, 3, 4, 5 };422 var array = [5]u8{ 1, 2, 3, 4, 5 };
416 var slice = array[1..3];423 const slice = array[1..3];
417 try comptime expect(@TypeOf(slice) == *[2]u8);424 try comptime expect(@TypeOf(slice) == *[2]u8);
418 try expect(slice[0] == 2);425 try expect(slice[0] == 2);
419 try expect(slice[1] == 3);426 try expect(slice[1] == 3);
...@@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" {...@@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" {
430 fn testArray0() !void {437 fn testArray0() !void {
431 {438 {
432 var array = [0]u8{};439 var array = [0]u8{};
433 var slice = array[0..0];440 const slice = array[0..0];
434 try comptime expect(@TypeOf(slice) == *[0]u8);441 try comptime expect(@TypeOf(slice) == *[0]u8);
435 }442 }
436 {443 {
437 var array = [0:0]u8{};444 var array = [0:0]u8{};
438 var slice = array[0..0];445 const slice = array[0..0];
439 try comptime expect(@TypeOf(slice) == *[0:0]u8);446 try comptime expect(@TypeOf(slice) == *[0:0]u8);
440 try expect(slice[0] == 0);447 try expect(slice[0] == 0);
441 }448 }
...@@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" {
443450
444 fn testArrayAlign() !void {451 fn testArrayAlign() !void {
445 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };452 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
446 var slice = array[4..5];453 const slice = array[4..5];
447 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);454 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
448 try expect(slice[0] == 5);455 try expect(slice[0] == 5);
449 try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);456 try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
...@@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" {
452 fn testPointer() !void {459 fn testPointer() !void {
453 var array = [5]u8{ 1, 2, 3, 4, 5 };460 var array = [5]u8{ 1, 2, 3, 4, 5 };
454 var pointer: [*]u8 = &array;461 var pointer: [*]u8 = &array;
455 var slice = pointer[1..3];462 const slice = pointer[1..3];
456 try comptime expect(@TypeOf(slice) == *[2]u8);463 try comptime expect(@TypeOf(slice) == *[2]u8);
457 try expect(slice[0] == 2);464 try expect(slice[0] == 2);
458 try expect(slice[1] == 3);465 try expect(slice[1] == 3);
...@@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" {
467474
468 fn testPointer0() !void {475 fn testPointer0() !void {
469 var pointer: [*]const u0 = &[1]u0{0};476 var pointer: [*]const u0 = &[1]u0{0};
470 var slice = pointer[0..1];477 const slice = pointer[0..1];
471 try comptime expect(@TypeOf(slice) == *const [1]u0);478 try comptime expect(@TypeOf(slice) == *const [1]u0);
472 try expect(slice[0] == 0);479 try expect(slice[0] == 0);
473 }480 }
...@@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" {
475 fn testPointerAlign() !void {482 fn testPointerAlign() !void {
476 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };483 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
477 var pointer: [*]align(4) u8 = &array;484 var pointer: [*]align(4) u8 = &array;
478 var slice = pointer[4..5];485 const slice = pointer[4..5];
479 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);486 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
480 try expect(slice[0] == 5);487 try expect(slice[0] == 5);
481 try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);488 try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
...@@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" {
484 fn testSlice() !void {491 fn testSlice() !void {
485 var array = [5]u8{ 1, 2, 3, 4, 5 };492 var array = [5]u8{ 1, 2, 3, 4, 5 };
486 var src_slice: []u8 = &array;493 var src_slice: []u8 = &array;
487 var slice = src_slice[1..3];494 const slice = src_slice[1..3];
488 try comptime expect(@TypeOf(slice) == *[2]u8);495 try comptime expect(@TypeOf(slice) == *[2]u8);
489 try expect(slice[0] == 2);496 try expect(slice[0] == 2);
490 try expect(slice[1] == 3);497 try expect(slice[1] == 3);
...@@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" {...@@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" {
513 fn testSliceAlign() !void {520 fn testSliceAlign() !void {
514 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };521 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
515 var src_slice: []align(4) u8 = &array;522 var src_slice: []align(4) u8 = &array;
516 var slice = src_slice[4..5];523 const slice = src_slice[4..5];
517 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);524 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
518 try expect(slice[0] == 5);525 try expect(slice[0] == 5);
519 try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);526 try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
...@@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" {...@@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" {
616 {623 {
617 var array = [0]u8{};624 var array = [0]u8{};
618 var src_slice: []u8 = &array;625 var src_slice: []u8 = &array;
619 var slice = src_slice[0..0];626 const slice = src_slice[0..0];
620 try expect(@TypeOf(slice) == *[0]u8);627 try expect(@TypeOf(slice) == *[0]u8);
621 }628 }
622 {629 {
623 var array = [0:0]u8{};630 var array = [0:0]u8{};
624 var src_slice: [:0]u8 = &array;631 var src_slice: [:0]u8 = &array;
625 var slice = src_slice[0..0];632 const slice = src_slice[0..0];
626 try expect(@TypeOf(slice) == *[0:0]u8);633 try expect(@TypeOf(slice) == *[0:0]u8);
627 }634 }
628 }635 }
...@@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" {...@@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" {
630 {637 {
631 var array = [0]u8{};638 var array = [0]u8{};
632 var src_slice: []u8 = &array;639 var src_slice: []u8 = &array;
633 var slice = src_slice[0..0];640 const slice = src_slice[0..0];
634 try comptime expect(@TypeOf(slice) == *[0]u8);641 try comptime expect(@TypeOf(slice) == *[0]u8);
635 }642 }
636 {643 {
637 var array = [0:0]u8{};644 var array = [0:0]u8{};
638 var src_slice: [:0]u8 = &array;645 var src_slice: [:0]u8 = &array;
639 var slice = src_slice[0..0];646 const slice = src_slice[0..0];
640 try comptime expect(@TypeOf(slice) == *[0]u8);647 try comptime expect(@TypeOf(slice) == *[0]u8);
641 }648 }
642}649}
...@@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" {...@@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" {
655662
656 fn doTheTest() !void {663 fn doTheTest() !void {
657 var x1: u8 = 42;664 var x1: u8 = 42;
665 _ = &x1;
658 const t1 = &.{ x1, 56, 54 };666 const t1 = &.{ x1, 56, 54 };
659 var slice1: []const u8 = t1;667 const slice1: []const u8 = t1;
660 try expect(slice1.len == 3);668 try expect(slice1.len == 3);
661 try expect(slice1[0] == 42);669 try expect(slice1[0] == 42);
662 try expect(slice1[1] == 56);670 try expect(slice1[1] == 56);
663 try expect(slice1[2] == 54);671 try expect(slice1[2] == 54);
664672
665 var x2: []const u8 = "hello";673 var x2: []const u8 = "hello";
674 _ = &x2;
666 const t2 = &.{ x2, ", ", "world!" };675 const t2 = &.{ x2, ", ", "world!" };
667 // @compileLog(@TypeOf(t2));676 // @compileLog(@TypeOf(t2));
668 var slice2: []const []const u8 = t2;677 const slice2: []const []const u8 = t2;
669 try expect(slice2.len == 3);678 try expect(slice2.len == 3);
670 try expect(mem.eql(u8, slice2[0], "hello"));679 try expect(mem.eql(u8, slice2[0], "hello"));
671 try expect(mem.eql(u8, slice2[1], ", "));680 try expect(mem.eql(u8, slice2[1], ", "));
...@@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" {...@@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" {
680 comptime {689 comptime {
681 var a: []const u8 = "aoeu";690 var a: []const u8 = "aoeu";
682 var b: []const u8 = "asdf";691 var b: []const u8 = "asdf";
692 _ = .{ &a, &b };
683 const c = a ++ b;693 const c = a ++ b;
684 try expect(std.mem.eql(u8, c, "aoeuasdf"));694 try expect(std.mem.eql(u8, c, "aoeuasdf"));
685 try expect(@TypeOf(c) == *const [8]u8);695 try expect(@TypeOf(c) == *const [8]u8);
...@@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" {...@@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" {
689test "array mult of slice gives ptr to array" {699test "array mult of slice gives ptr to array" {
690 comptime {700 comptime {
691 var a: []const u8 = "aoeu";701 var a: []const u8 = "aoeu";
702 _ = &a;
692 const c = a ** 2;703 const c = a ** 2;
693 try expect(std.mem.eql(u8, c, "aoeuaoeu"));704 try expect(std.mem.eql(u8, c, "aoeuaoeu"));
694 try expect(@TypeOf(c) == *const [8]u8);705 try expect(@TypeOf(c) == *const [8]u8);
...@@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" {...@@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" {
736 const S = struct {747 const S = struct {
737 fn do() !void {748 fn do() !void {
738 var array = [_:0]u8{ 1, 2, 3, 4 };749 var array = [_:0]u8{ 1, 2, 3, 4 };
739 var slice = array[4..5];750 const slice = array[4..5];
740 try expect(slice.len == 1);751 try expect(slice.len == 1);
741 try expect(slice[0] == 0);752 try expect(slice[0] == 0);
742 try expect(@TypeOf(slice) == *[1]u8);753 try expect(@TypeOf(slice) == *[1]u8);
...@@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" {...@@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" {
754 const S = struct {765 const S = struct {
755 fn do() !void {766 fn do() !void {
756 var array = [_:0]u8{ 1, 2, 3, 4 };767 var array = [_:0]u8{ 1, 2, 3, 4 };
757 var src_slice: [:0]u8 = &array;768 const src_slice: [:0]u8 = &array;
758 var slice = src_slice[4..5];769 const slice = src_slice[4..5];
759 try expect(slice.len == 1);770 try expect(slice.len == 1);
760 try expect(slice[0] == 0);771 try expect(slice[0] == 0);
761 try expect(@TypeOf(slice) == *[1]u8);772 try expect(@TypeOf(slice) == *[1]u8);
...@@ -820,6 +831,7 @@ test "global slice field access" {...@@ -820,6 +831,7 @@ test "global slice field access" {
820831
821test "slice of void" {832test "slice of void" {
822 var n: usize = 10;833 var n: usize = 10;
834 _ = &n;
823 var arr: [12]void = undefined;835 var arr: [12]void = undefined;
824 const slice = @as([]void, &arr)[0..n];836 const slice = @as([]void, &arr)[0..n];
825 try expect(slice.len == n);837 try expect(slice.len == n);
...@@ -827,7 +839,7 @@ test "slice of void" {...@@ -827,7 +839,7 @@ test "slice of void" {
827839
828test "slice with dereferenced value" {840test "slice with dereferenced value" {
829 var a: usize = 0;841 var a: usize = 0;
830 var idx: *usize = &a;842 const idx: *usize = &a;
831 _ = blk: {843 _ = blk: {
832 var array = [_]u8{};844 var array = [_]u8{};
833 break :blk array[idx.*..];845 break :blk array[idx.*..];
test/behavior/struct.zig+44-21
...@@ -254,7 +254,8 @@ test "struct field init with catch" {...@@ -254,7 +254,8 @@ test "struct field init with catch" {
254 const S = struct {254 const S = struct {
255 fn doTheTest() !void {255 fn doTheTest() !void {
256 var x: anyerror!isize = 1;256 var x: anyerror!isize = 1;
257 var req = Foo{257 _ = &x;
258 const req = Foo{
258 .field = x catch undefined,259 .field = x catch undefined,
259 };260 };
260 try expect(req.field == 1);261 try expect(req.field == 1);
...@@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" {...@@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" {
505 var all: u64 = 0x7765443322221111;506 var all: u64 = 0x7765443322221111;
506 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;507 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;
507 @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all)));508 @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all)));
508 var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;509 const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;
509510
510 try expect(bitfields.f1 == 0x1111);511 try expect(bitfields.f1 == 0x1111);
511 try expect(bitfields.f2 == 0x2222);512 try expect(bitfields.f2 == 0x2222);
...@@ -545,7 +546,7 @@ test "zero-bit field in packed struct" {...@@ -545,7 +546,7 @@ test "zero-bit field in packed struct" {
545 y: void,546 y: void,
546 };547 };
547 var x: S = undefined;548 var x: S = undefined;
548 _ = x;549 _ = &x;
549}550}
550551
551test "packed struct with non-ABI-aligned field" {552test "packed struct with non-ABI-aligned field" {
...@@ -624,6 +625,7 @@ test "default struct initialization fields" {...@@ -624,6 +625,7 @@ test "default struct initialization fields" {
624 .b = 5,625 .b = 5,
625 };626 };
626 var five: i32 = 5;627 var five: i32 = 5;
628 _ = &five;
627 const y = S{629 const y = S{
628 .b = five,630 .b = five,
629 };631 };
...@@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" {...@@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" {
714 };716 };
715717
716 var s = S{ .a = 2, .b = 0 };718 var s = S{ .a = 2, .b = 0 };
717 var b_ptr = &s.b;719 const b_ptr = &s.b;
718 try expect(s.b == 0);720 try expect(s.b == 0);
719 b_ptr.* = 2;721 b_ptr.* = 2;
720 try expect(s.b == 2);722 try expect(s.b == 2);
...@@ -727,6 +729,7 @@ test "packed struct with u0 field access" {...@@ -727,6 +729,7 @@ test "packed struct with u0 field access" {
727 f0: u0,729 f0: u0,
728 };730 };
729 var s = S{ .f0 = 0 };731 var s = S{ .f0 = 0 };
732 _ = &s;
730 try comptime expect(s.f0 == 0);733 try comptime expect(s.f0 == 0);
731}734}
732735
...@@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" {...@@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" {
788791
789 const S = struct {792 const S = struct {
790 fn entry() !void {793 fn entry() !void {
791 var x = makeBar(10);794 const x = makeBar(10);
792 try expect(@as(i32, 10) == x.handle);795 try expect(@as(i32, 10) == x.handle);
793 }796 }
794797
...@@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" {...@@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" {
827 var s = &sx;830 var s = &sx;
828 try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2"));831 try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2"));
829 var v2 = U{ .Num = 123 };832 var v2 = U{ .Num = 123 };
833 _ = &v2;
830 s.f2 = v2;834 s.f2 = v2;
831 try expect(s.f2.Num == 123);835 try expect(s.f2.Num == 123);
832}836}
...@@ -852,7 +856,7 @@ test "packed struct field passed to generic function" {...@@ -852,7 +856,7 @@ test "packed struct field passed to generic function" {
852856
853 var p: S.P = undefined;857 var p: S.P = undefined;
854 p.b = 29;858 p.b = 29;
855 var loaded = S.genericReadPackedField(&p.b);859 const loaded = S.genericReadPackedField(&p.b);
856 try expect(loaded == 29);860 try expect(loaded == 29);
857}861}
858862
...@@ -871,6 +875,7 @@ test "anonymous struct literal syntax" {...@@ -871,6 +875,7 @@ test "anonymous struct literal syntax" {
871 .x = 1,875 .x = 1,
872 .y = 2,876 .y = 2,
873 };877 };
878 _ = &p;
874 try expect(p.x == 1);879 try expect(p.x == 1);
875 try expect(p.y == 2);880 try expect(p.y == 2);
876 }881 }
...@@ -920,6 +925,7 @@ test "fully anonymous list literal" {...@@ -920,6 +925,7 @@ test "fully anonymous list literal" {
920925
921test "tuple assigned to variable" {926test "tuple assigned to variable" {
922 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };927 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
928 _ = &vec;
923 try expect(vec.@"0" == 22);929 try expect(vec.@"0" == 22);
924 try expect(vec.@"1" == 55);930 try expect(vec.@"1" == 55);
925 try expect(vec.@"2" == 99);931 try expect(vec.@"2" == 99);
...@@ -940,6 +946,7 @@ test "comptime struct field" {...@@ -940,6 +946,7 @@ test "comptime struct field" {
940 comptime std.debug.assert(@sizeOf(T) == 4);946 comptime std.debug.assert(@sizeOf(T) == 4);
941947
942 var foo: T = undefined;948 var foo: T = undefined;
949 _ = &foo;
943 try comptime expect(foo.b == 1234);950 try comptime expect(foo.b == 1234);
944}951}
945952
...@@ -950,7 +957,7 @@ test "tuple element initialized with fn call" {...@@ -950,7 +957,7 @@ test "tuple element initialized with fn call" {
950957
951 const S = struct {958 const S = struct {
952 fn doTheTest() !void {959 fn doTheTest() !void {
953 var x = .{foo()};960 const x = .{foo()};
954 try expectEqualSlices(u8, x[0], "hi");961 try expectEqualSlices(u8, x[0], "hi");
955 }962 }
956 fn foo() []const u8 {963 fn foo() []const u8 {
...@@ -977,6 +984,7 @@ test "struct with union field" {...@@ -977,6 +984,7 @@ test "struct with union field" {
977 var True = Value{984 var True = Value{
978 .kind = .{ .Bool = true },985 .kind = .{ .Bool = true },
979 };986 };
987 _ = &True;
980 try expect(@as(u32, 2) == True.ref);988 try expect(@as(u32, 2) == True.ref);
981 try expect(True.kind.Bool);989 try expect(True.kind.Bool);
982}990}
...@@ -996,6 +1004,7 @@ test "struct with 0-length union array field" {...@@ -996,6 +1004,7 @@ test "struct with 0-length union array field" {
996 };1004 };
9971005
998 var s: S = undefined;1006 var s: S = undefined;
1007 _ = &s;
999 try expectEqual(@as(usize, 0), s.zero_length.len);1008 try expectEqual(@as(usize, 0), s.zero_length.len);
1000}1009}
10011010
...@@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" {...@@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" {
10191028
1020 fn doTheTest() !void {1029 fn doTheTest() !void {
1021 var y: u32 = 42;1030 var y: u32 = 42;
1031 _ = &y;
1022 const t0 = .{ .A = 123, .B = "foo", .C = {} };1032 const t0 = .{ .A = 123, .B = "foo", .C = {} };
1023 const t1 = .{ .A = y, .B = "foo", .C = {} };1033 const t1 = .{ .A = y, .B = "foo", .C = {} };
1024 const y0: S2 = t0;1034 const y0: S2 = t0;
1025 var y1: S2 = t1;1035 const y1: S2 = t1;
1026 try expect(y0.A == 123);1036 try expect(y0.A == 123);
1027 try expect(std.mem.eql(u8, y0.B, "foo"));1037 try expect(std.mem.eql(u8, y0.B, "foo"));
1028 try expect(y0.C == {});1038 try expect(y0.C == {});
...@@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {...@@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {
10571067
1058 fn doTheTest() !void {1068 fn doTheTest() !void {
1059 var y: u32 = 42;1069 var y: u32 = 42;
1070 _ = &y;
1060 const t0 = &.{ .A = 123, .B = "foo", .C = {} };1071 const t0 = &.{ .A = 123, .B = "foo", .C = {} };
1061 const t1 = &.{ .A = y, .B = "foo", .C = {} };1072 const t1 = &.{ .A = y, .B = "foo", .C = {} };
1062 const y0: *const S2 = t0;1073 const y0: *const S2 = t0;
1063 var y1: *const S2 = t1;1074 const y1: *const S2 = t1;
1064 try expect(y0.A == 123);1075 try expect(y0.A == 123);
1065 try expect(std.mem.eql(u8, y0.B, "foo"));1076 try expect(std.mem.eql(u8, y0.B, "foo"));
1066 try expect(y0.C == {});1077 try expect(y0.C == {});
...@@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" {...@@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" {
1161 }1172 }
11621173
1163 fn doTheTest() !void {1174 fn doTheTest() !void {
1164 var a = try (try foo()).?;1175 const a = try (try foo()).?;
1165 var b = try bar().?;1176 const b = try bar().?;
1166 try expect(a.a + b[1] == 3);1177 try expect(a.a + b[1] == 3);
1167 }1178 }
1168 };1179 };
...@@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" {...@@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" {
1227 }1238 }
12281239
1229 fn doTheTest() !void {1240 fn doTheTest() !void {
1230 var a = try (try foo()).?;1241 const a = try (try foo()).?;
1231 var b = try bar().?;1242 const b = try bar().?;
1232 try expect(a.a + b[1] == 3);1243 try expect(a.a + b[1] == 3);
1233 }1244 }
1234 };1245 };
...@@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" {...@@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" {
12431254
1244 const S = struct { x: i32 = 1234 };1255 const S = struct { x: i32 = 1234 };
1245 var s: S = .{};1256 var s: S = .{};
1257 _ = &s;
1246 try expect(s.x == 1234);1258 try expect(s.x == 1234);
1247}1259}
12481260
...@@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" {...@@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" {
1301 fn doTheTest() !void {1313 fn doTheTest() !void {
1302 const S = packed struct { a: u30 };1314 const S = packed struct { a: u30 };
1303 var s1: S = .{ .a = 1 };1315 var s1: S = .{ .a = 1 };
1304 var s2 = &s1;1316 const s2 = &s1;
1305 try expect(s2.a == 1);1317 try expect(s2.a == 1);
1306 var s3: S = undefined;1318 var s3: S = undefined;
1307 var s4 = &s3;1319 const s4 = &s3;
1308 _ = s4;1320 _ = s4;
1309 }1321 }
1310 };1322 };
...@@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" {...@@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" {
1343 };1355 };
1344 };1356 };
1345 var s: namespace.S = .{ .blah = 1234 };1357 var s: namespace.S = .{ .blah = 1234 };
1358 _ = &s;
1346 try expect(s.size == 4);1359 try expect(s.size == 4);
1347}1360}
13481361
...@@ -1362,6 +1375,7 @@ test "under-aligned struct field" {...@@ -1362,6 +1375,7 @@ test "under-aligned struct field" {
1362 data: U align(4),1375 data: U align(4),
1363 };1376 };
1364 var runtime: usize = 1234;1377 var runtime: usize = 1234;
1378 _ = &runtime;
1365 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };1379 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };
1366 const array = @as(*const [12]u8, @ptrCast(ptr));1380 const array = @as(*const [12]u8, @ptrCast(ptr));
1367 const result = std.mem.readInt(u64, array[4..12], native_endian);1381 const result = std.mem.readInt(u64, array[4..12], native_endian);
...@@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" {...@@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" {
1509 }1523 }
1510 };1524 };
1511 var a = A.f();1525 var a = A.f();
1526 _ = &a;
1512 try expect(a.f == A.f);1527 try expect(a.f == A.f);
1513}1528}
15141529
...@@ -1538,7 +1553,8 @@ test "optional field init with tuple" {...@@ -1538,7 +1553,8 @@ test "optional field init with tuple" {
1538 a: ?struct { b: u32 },1553 a: ?struct { b: u32 },
1539 };1554 };
1540 var a: u32 = 0;1555 var a: u32 = 0;
1541 var b = S{1556 _ = &a;
1557 const b = S{
1542 .a = .{ .b = a },1558 .a = .{ .b = a },
1543 };1559 };
1544 try expect(b.a.?.b == a);1560 try expect(b.a.?.b == a);
...@@ -1550,7 +1566,8 @@ test "if inside struct init inside if" {...@@ -1550,7 +1566,8 @@ test "if inside struct init inside if" {
1550 const MyStruct = struct { x: u32 };1566 const MyStruct = struct { x: u32 };
1551 const b: u32 = 5;1567 const b: u32 = 5;
1552 var i: u32 = 1;1568 var i: u32 = 1;
1553 var my_var = if (i < 5)1569 _ = &i;
1570 const my_var = if (i < 5)
1554 MyStruct{1571 MyStruct{
1555 .x = 1 + if (i > 0) b else 0,1572 .x = 1 + if (i > 0) b else 0,
1556 }1573 }
...@@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" {...@@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" {
1599 var things = struct {1616 var things = struct {
1600 comptime foo: i8 = 1,1617 comptime foo: i8 = 1,
1601 }{};1618 }{};
16021619 _ = &things;
1603 comptime std.debug.assert(things.foo == 1);1620 comptime std.debug.assert(things.foo == 1);
1604 }1621 }
16051622
...@@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" {...@@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" {
1608 comptime foo: i8 = 1,1625 comptime foo: i8 = 1,
1609 };1626 };
1610 var things = T{};1627 var things = T{};
16111628 _ = &things;
1612 comptime std.debug.assert(things.foo == 1);1629 comptime std.debug.assert(things.foo == 1);
1613 }1630 }
16141631
...@@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" {...@@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" {
1616 var things: struct {1633 var things: struct {
1617 comptime foo: i8 = 1,1634 comptime foo: i8 = 1,
1618 } = .{};1635 } = .{};
16191636 _ = &things;
1620 comptime std.debug.assert(things.foo == 1);1637 comptime std.debug.assert(things.foo == 1);
1621 }1638 }
16221639
...@@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" {...@@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" {
1624 var things: struct {1641 var things: struct {
1625 comptime foo: i8 = 1,1642 comptime foo: i8 = 1,
1626 } = undefined; // Segmentation fault at address 0x01643 } = undefined; // Segmentation fault at address 0x0
16271644 _ = &things;
1628 comptime std.debug.assert(things.foo == 1);1645 comptime std.debug.assert(things.foo == 1);
1629 }1646 }
1630}1647}
...@@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" {...@@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" {
1755test "pointer to struct initialized through reference to anonymous initializer provides result types" {1772test "pointer to struct initialized through reference to anonymous initializer provides result types" {
1756 const S = struct { a: u8, b: u16, c: *const anyopaque };1773 const S = struct { a: u8, b: u16, c: *const anyopaque };
1757 var my_u16: u16 = 0xABCD;1774 var my_u16: u16 = 0xABCD;
1775 _ = &my_u16;
1758 const s: *const S = &.{1776 const s: *const S = &.{
1759 // intentionally out of order1777 // intentionally out of order
1760 .c = @ptrCast("hello"),1778 .c = @ptrCast("hello"),
...@@ -1792,6 +1810,7 @@ test "initializer uses own alignment" {...@@ -1792,6 +1810,7 @@ test "initializer uses own alignment" {
1792 };1810 };
17931811
1794 var s: S = .{};1812 var s: S = .{};
1813 _ = &s;
1795 try expectEqual(4, @alignOf(S));1814 try expectEqual(4, @alignOf(S));
1796 try expectEqual(@as(usize, 5), s.x);1815 try expectEqual(@as(usize, 5), s.x);
1797}1816}
...@@ -1802,6 +1821,7 @@ test "initializer uses own size" {...@@ -1802,6 +1821,7 @@ test "initializer uses own size" {
1802 };1821 };
18031822
1804 var s: S = .{};1823 var s: S = .{};
1824 _ = &s;
1805 try expectEqual(4, @sizeOf(S));1825 try expectEqual(4, @sizeOf(S));
1806 try expectEqual(@as(usize, 5), s.x);1826 try expectEqual(@as(usize, 5), s.x);
1807}1827}
...@@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" {...@@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" {
18151835
1816 fn doTheTest() !void {1836 fn doTheTest() !void {
1817 var foo: S = .{};1837 var foo: S = .{};
1838 _ = &foo;
1818 try expectEqual(&S.instance, foo.s);1839 try expectEqual(&S.instance, foo.s);
1819 }1840 }
1820 };1841 };
...@@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" {...@@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" {
1839 };1860 };
1840 };1861 };
1841 var outer: S.StructOuter = .{};1862 var outer: S.StructOuter = .{};
1863 _ = &outer;
1842 try expect(outer.middle.outer == null);1864 try expect(outer.middle.outer == null);
1843 try expect(outer.middle.inner == null);1865 try expect(outer.middle.inner == null);
1844}1866}
...@@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" {...@@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" {
1855 }1877 }
1856 };1878 };
1857 var s: S = .{};1879 var s: S = .{};
1880 _ = &s;
1858 try expect(s.x == 123);1881 try expect(s.x == 123);
1859}1882}
test/behavior/struct_contains_null_ptr_itself.zig+1
...@@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" {...@@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" {
7 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO7 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
88
9 var x: ?*NodeLineComment = null;9 var x: ?*NodeLineComment = null;
10 _ = &x;
10 try expect(x == null);11 try expect(x == null);
11}12}
1213
test/behavior/switch.zig+17-9
...@@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {...@@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
157157
158test "u0" {158test "u0" {
159 var val: u0 = 0;159 var val: u0 = 0;
160 _ = &val;
160 switch (val) {161 switch (val) {
161 0 => try expect(val == 0),162 0 => try expect(val == 0),
162 }163 }
...@@ -164,6 +165,7 @@ test "u0" {...@@ -164,6 +165,7 @@ test "u0" {
164165
165test "undefined.u0" {166test "undefined.u0" {
166 var val: u0 = undefined;167 var val: u0 = undefined;
168 _ = &val;
167 switch (val) {169 switch (val) {
168 0 => try expect(val == 0),170 0 => try expect(val == 0),
169 }171 }
...@@ -173,6 +175,7 @@ test "switch with disjoint range" {...@@ -173,6 +175,7 @@ test "switch with disjoint range" {
173 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO175 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
174176
175 var q: u8 = 0;177 var q: u8 = 0;
178 _ = &q;
176 switch (q) {179 switch (q) {
177 0...125 => {},180 0...125 => {},
178 127...255 => {},181 127...255 => {},
...@@ -183,12 +186,8 @@ test "switch with disjoint range" {...@@ -183,12 +186,8 @@ test "switch with disjoint range" {
183test "switch variable for range and multiple prongs" {186test "switch variable for range and multiple prongs" {
184 const S = struct {187 const S = struct {
185 fn doTheTest() !void {188 fn doTheTest() !void {
186 var u: u8 = 16;189 try doTheSwitch(16);
187 try doTheSwitch(u);190 try doTheSwitch(42);
188 try comptime doTheSwitch(u);
189 var v: u8 = 42;
190 try doTheSwitch(v);
191 try comptime doTheSwitch(v);
192 }191 }
193 fn doTheSwitch(q: u8) !void {192 fn doTheSwitch(q: u8) !void {
194 switch (q) {193 switch (q) {
...@@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" {...@@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" {
198 }197 }
199 }198 }
200 };199 };
201 _ = S;200 try S.doTheTest();
201 try comptime S.doTheTest();
202}202}
203203
204var state: u32 = 0;204var state: u32 = 0;
...@@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" {...@@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" {
322 };322 };
323323
324 var x: X = X{ .b = 10 };324 var x: X = X{ .b = 10 };
325 var y: i32 = switch (x) {325 _ = &x;
326 const y: i32 = switch (x) {
326 .a => unreachable,327 .a => unreachable,
327 .b => |b| b + 1,328 .b => |b| b + 1,
328 };329 };
...@@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" {...@@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" {
357 };358 };
358359
359 var foo = Foo{ .a = 1234 };360 var foo = Foo{ .a = 1234 };
361 _ = &foo;
360 switch (foo) {362 switch (foo) {
361 .a => |x| {363 .a => |x| {
362 try expect(x == 1234);364 try expect(x == 1234);
...@@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" {...@@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" {
406 const S = struct {408 const S = struct {
407 fn doTheTest() !void {409 fn doTheTest() !void {
408 var x: i32 = 5;410 var x: i32 = 5;
411 _ = &x;
409 switch (x + 10) {412 switch (x + 10) {
410 14 => @panic("fail"),413 14 => @panic("fail"),
411 16 => @panic("fail"),414 16 => @panic("fail"),
...@@ -606,6 +609,7 @@ test "switch on error set with single else" {...@@ -606,6 +609,7 @@ test "switch on error set with single else" {
606 const S = struct {609 const S = struct {
607 fn doTheTest() !void {610 fn doTheTest() !void {
608 var some: error{Foo} = error.Foo;611 var some: error{Foo} = error.Foo;
612 _ = &some;
609 try expect(switch (some) {613 try expect(switch (some) {
610 else => blk: {614 else => blk: {
611 break :blk true;615 break :blk true;
...@@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" {...@@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" {
672 b = 2,676 b = 2,
673 _,677 _,
674 };678 };
675 var e: E = @as(E, @enumFromInt(0));679 var e: E = @enumFromInt(0);
680 _ = &e;
676 switch (e) {681 switch (e) {
677 @as(E, @enumFromInt(0)) => {},682 @as(E, @enumFromInt(0)) => {},
678 .a => return error.TestFailed,683 .a => return error.TestFailed,
...@@ -685,6 +690,7 @@ test "switch item sizeof" {...@@ -685,6 +690,7 @@ test "switch item sizeof" {
685 const S = struct {690 const S = struct {
686 fn doTheTest() !void {691 fn doTheTest() !void {
687 var a: usize = 0;692 var a: usize = 0;
693 _ = &a;
688 switch (a) {694 switch (a) {
689 @sizeOf(struct {}) => {},695 @sizeOf(struct {}) => {},
690 else => return error.TestFailed,696 else => return error.TestFailed,
...@@ -699,6 +705,7 @@ test "comptime inline switch" {...@@ -699,6 +705,7 @@ test "comptime inline switch" {
699 const U = union(enum) { a: type, b: type };705 const U = union(enum) { a: type, b: type };
700 const value = comptime blk: {706 const value = comptime blk: {
701 var u: U = .{ .a = u32 };707 var u: U = .{ .a = u32 };
708 _ = &u;
702 break :blk switch (u) {709 break :blk switch (u) {
703 inline .a, .b => |v| v,710 inline .a, .b => |v| v,
704 };711 };
...@@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" {...@@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" {
814821
815 // This is runtime-known so the following store isn't comptime-known.822 // This is runtime-known so the following store isn't comptime-known.
816 var rt: u32 = 123;823 var rt: u32 = 123;
824 _ = &rt;
817 val = .{ .a = rt }; // will not necessarily zero remaning payload memory825 val = .{ .a = rt }; // will not necessarily zero remaning payload memory
818826
819 // Fields intentionally backwards here827 // Fields intentionally backwards here
test/behavior/truncate.zig+17-12
...@@ -4,58 +4,62 @@ const expect = std.testing.expect;...@@ -4,58 +4,62 @@ const expect = std.testing.expect;
44
5test "truncate u0 to larger integer allowed and has comptime-known result" {5test "truncate u0 to larger integer allowed and has comptime-known result" {
6 var x: u0 = 0;6 var x: u0 = 0;
7 _ = &x;
7 const y = @as(u8, @truncate(x));8 const y = @as(u8, @truncate(x));
8 try comptime expect(y == 0);9 try comptime expect(y == 0);
9}10}
1011
11test "truncate.u0.literal" {12test "truncate.u0.literal" {
12 var z = @as(u0, @truncate(0));13 const z: u0 = @truncate(0);
13 try expect(z == 0);14 try expect(z == 0);
14}15}
1516
16test "truncate.u0.const" {17test "truncate.u0.const" {
17 const c0: usize = 0;18 const c0: usize = 0;
18 var z = @as(u0, @truncate(c0));19 const z: u0 = @truncate(c0);
19 try expect(z == 0);20 try expect(z == 0);
20}21}
2122
22test "truncate.u0.var" {23test "truncate.u0.var" {
23 var d: u8 = 2;24 var d: u8 = 2;
24 var z = @as(u0, @truncate(d));25 _ = &d;
26 const z: u0 = @truncate(d);
25 try expect(z == 0);27 try expect(z == 0);
26}28}
2729
28test "truncate i0 to larger integer allowed and has comptime-known result" {30test "truncate i0 to larger integer allowed and has comptime-known result" {
29 var x: i0 = 0;31 var x: i0 = 0;
30 const y = @as(i8, @truncate(x));32 _ = &x;
33 const y: i8 = @truncate(x);
31 try comptime expect(y == 0);34 try comptime expect(y == 0);
32}35}
3336
34test "truncate.i0.literal" {37test "truncate.i0.literal" {
35 var z = @as(i0, @truncate(0));38 const z: i0 = @truncate(0);
36 try expect(z == 0);39 try expect(z == 0);
37}40}
3841
39test "truncate.i0.const" {42test "truncate.i0.const" {
40 const c0: isize = 0;43 const c0: isize = 0;
41 var z = @as(i0, @truncate(c0));44 const z: i0 = @truncate(c0);
42 try expect(z == 0);45 try expect(z == 0);
43}46}
4447
45test "truncate.i0.var" {48test "truncate.i0.var" {
46 var d: i8 = 2;49 var d: i8 = 2;
47 var z = @as(i0, @truncate(d));50 _ = &d;
51 const z: i0 = @truncate(d);
48 try expect(z == 0);52 try expect(z == 0);
49}53}
5054
51test "truncate on comptime integer" {55test "truncate on comptime integer" {
52 var x = @as(u16, @truncate(9999));56 const x: u16 = @truncate(9999);
53 try expect(x == 9999);57 try expect(x == 9999);
54 var y = @as(u16, @truncate(-21555));58 const y: u16 = @truncate(-21555);
55 try expect(y == 0xabcd);59 try expect(y == 0xabcd);
56 var z = @as(i16, @truncate(-65537));60 const z: i16 = @truncate(-65537);
57 try expect(z == -1);61 try expect(z == -1);
58 var w = @as(u1, @truncate(1 << 100));62 const w: u1 = @truncate(1 << 100);
59 try expect(w == 0);63 try expect(w == 0);
60}64}
6165
...@@ -69,7 +73,8 @@ test "truncate on vectors" {...@@ -69,7 +73,8 @@ test "truncate on vectors" {
69 const S = struct {73 const S = struct {
70 fn doTheTest() !void {74 fn doTheTest() !void {
71 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };75 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };
72 var v2: @Vector(4, u8) = @truncate(v1);76 _ = &v1;
77 const v2: @Vector(4, u8) = @truncate(v1);
73 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));78 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));
74 }79 }
75 };80 };
test/behavior/tuple.zig+25-8
...@@ -15,9 +15,10 @@ test "tuple concatenation" {...@@ -15,9 +15,10 @@ test "tuple concatenation" {
15 fn doTheTest() !void {15 fn doTheTest() !void {
16 var a: i32 = 1;16 var a: i32 = 1;
17 var b: i32 = 2;17 var b: i32 = 2;
18 var x = .{a};18 _ = .{ &a, &b };
19 var y = .{b};19 const x = .{a};
20 var c = x ++ y;20 const y = .{b};
21 const c = x ++ y;
21 try expect(@as(i32, 1) == c[0]);22 try expect(@as(i32, 1) == c[0]);
22 try expect(@as(i32, 2) == c[1]);23 try expect(@as(i32, 2) == c[1]);
23 }24 }
...@@ -119,7 +120,7 @@ test "tuple initializer for var" {...@@ -119,7 +120,7 @@ test "tuple initializer for var" {
119 .id = @as(usize, 2),120 .id = @as(usize, 2),
120 .name = Bytes{ .id = 20 },121 .name = Bytes{ .id = 20 },
121 };122 };
122 _ = tmp;123 _ = &tmp;
123 }124 }
124 };125 };
125126
...@@ -157,6 +158,7 @@ test "array-like initializer for tuple types" {...@@ -157,6 +158,7 @@ test "array-like initializer for tuple types" {
157 const S = struct {158 const S = struct {
158 fn doTheTest() !void {159 fn doTheTest() !void {
159 var obj: T = .{ -1234, 128 };160 var obj: T = .{ -1234, 128 };
161 _ = &obj;
160 try expect(@as(i32, -1234) == obj[0]);162 try expect(@as(i32, -1234) == obj[0]);
161 try expect(@as(u8, 128) == obj[1]);163 try expect(@as(u8, 128) == obj[1]);
162 }164 }
...@@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" {...@@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" {
171 fn doTheTest() !void {173 fn doTheTest() !void {
172 const precomputed = comptime blk: {174 const precomputed = comptime blk: {
173 var x: i32 = 1234;175 var x: i32 = 1234;
176 _ = &x;
174 break :blk .{177 break :blk .{
175 .x = x,178 .x = x,
176 };179 };
...@@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" {...@@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" {
188 fn doTheTest() !void {191 fn doTheTest() !void {
189 const precomputed = comptime blk: {192 const precomputed = comptime blk: {
190 var x: i32 = 1234;193 var x: i32 = 1234;
194 _ = &x;
191 break :blk .{x};195 break :blk .{x};
192 };196 };
193 try expect(precomputed[0] == 1234);197 try expect(precomputed[0] == 1234);
...@@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" {...@@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" {
201test "initializing tuple with explicit type" {205test "initializing tuple with explicit type" {
202 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });206 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
203 var a = T{ 0, 0 };207 var a = T{ 0, 0 };
204 _ = a;208 _ = &a;
205}209}
206210
207test "initializing anon struct with explicit type" {211test "initializing anon struct with explicit type" {
208 const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) });212 const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) });
209 var a = T{ .foo = 1, .bar = 2 };213 var a = T{ .foo = 1, .bar = 2 };
210 _ = a;214 _ = &a;
211}215}
212216
213test "fieldParentPtr of tuple" {217test "fieldParentPtr of tuple" {
...@@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" {...@@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" {
216 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO220 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
217221
218 var x: u32 = 0;222 var x: u32 = 0;
223 _ = &x;
219 const tuple = .{ x, x };224 const tuple = .{ x, x };
220 try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1]));225 try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1]));
221}226}
...@@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" {...@@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" {
226 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO231 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
227232
228 var x: u32 = 0;233 var x: u32 = 0;
234 _ = &x;
229 const anon_st = .{ .foo = x, .bar = x };235 const anon_st = .{ .foo = x, .bar = x };
230 try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar));236 try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar));
231}237}
232238
233test "offsetOf tuple" {239test "offsetOf tuple" {
234 var x: u32 = 0;240 var x: u32 = 0;
241 _ = &x;
235 const T = @TypeOf(.{ x, x });242 const T = @TypeOf(.{ x, x });
236 try expect(@offsetOf(T, "1") == @sizeOf(u32));243 try expect(@offsetOf(T, "1") == @sizeOf(u32));
237}244}
238245
239test "offsetOf anon struct" {246test "offsetOf anon struct" {
240 var x: u32 = 0;247 var x: u32 = 0;
248 _ = &x;
241 const T = @TypeOf(.{ .foo = x, .bar = x });249 const T = @TypeOf(.{ .foo = x, .bar = x });
242 try expect(@offsetOf(T, "bar") == @sizeOf(u32));250 try expect(@offsetOf(T, "bar") == @sizeOf(u32));
243}251}
...@@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" {...@@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" {
247 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;255 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
248256
249 var x: u32 = 15;257 var x: u32 = 15;
258 _ = &x;
250 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });259 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
251 var a: T = .{ -1234, 5678, x + 1 };260 var a: T = .{ -1234, 5678, x + 1 };
261 _ = &a;
252 try expect(a[2] == 16);262 try expect(a[2] == 16);
253}263}
254264
...@@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" {...@@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" {
257 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;267 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
258268
259 var x: u32 = 15;269 var x: u32 = 15;
270 _ = &x;
260 const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x });271 const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x });
261 var a: T = .{ .foo = -1234, .bar = x + 1 };272 var a: T = .{ .foo = -1234, .bar = x + 1 };
273 _ = &a;
262 try expect(a.bar == 16);274 try expect(a.bar == 16);
263}275}
264276
...@@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" {...@@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" {
338350
339 const T = std.meta.Tuple(&[_]type{ usize, void });351 const T = std.meta.Tuple(&[_]type{ usize, void });
340 var t: T = .{ 5, {} };352 var t: T = .{ 5, {} };
353 _ = &t;
341 try expect(t[0] == 5);354 try expect(t[0] == 5);
342}355}
343356
...@@ -352,6 +365,7 @@ test "branching inside tuple literal" {...@@ -352,6 +365,7 @@ test "branching inside tuple literal" {
352 }365 }
353 };366 };
354 var a = false;367 var a = false;
368 _ = &a;
355 try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)});369 try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)});
356}370}
357371
...@@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" {...@@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" {
363 const E = union(enum) { e: []const u8 };377 const E = union(enum) { e: []const u8 };
364 const W = union(enum) { w: E };378 const W = union(enum) { w: E };
365 var e = E{ .e = "test" };379 var e = E{ .e = "test" };
380 _ = &e;
366 const w = .{W{ .w = e }};381 const w = .{W{ .w = e }};
367 try expectEqualStrings(w[0].w.e, "test");382 try expectEqualStrings(w[0].w.e, "test");
368}383}
...@@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" {...@@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" {
388 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
389404
390 var data: u8 = 0;405 var data: u8 = 0;
406 _ = &data;
391 const x = .{407 const x = .{
392 if (data != 0) "" else switch (@as(u1, @truncate(data))) {408 if (data != 0) "" else switch (@as(u1, @truncate(data))) {
393 0 => "up",409 0 => "up",
...@@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" {...@@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" {
446462
447 var x: u8 = 1;463 var x: u8 = 1;
448 var y: u16 = 2;464 var y: u16 = 2;
449 var t = .{ x, y };465 _ = .{ &x, &y };
450 var s: struct { u8, u16 } = t;466 const t = .{ x, y };
467 const s: struct { u8, u16 } = t;
451 try expectEqual(x, s[0]);468 try expectEqual(x, s[0]);
452 try expectEqual(y, s[1]);469 try expectEqual(y, s[1]);
453}470}
test/behavior/tuple_declarations.zig+4-2
...@@ -38,17 +38,19 @@ test "Tuple declaration usage" {...@@ -38,17 +38,19 @@ test "Tuple declaration usage" {
3838
39 const T = struct { u32, []const u8 };39 const T = struct { u32, []const u8 };
40 var t: T = .{ 1, "foo" };40 var t: T = .{ 1, "foo" };
41 _ = &t;
41 try expect(t[0] == 1);42 try expect(t[0] == 1);
42 try expectEqualStrings(t[1], "foo");43 try expectEqualStrings(t[1], "foo");
4344
44 var mul = t ** 3;45 const mul = t ** 3;
45 try expect(@TypeOf(mul) != T);46 try expect(@TypeOf(mul) != T);
46 try expect(mul.len == 6);47 try expect(mul.len == 6);
47 try expect(mul[2] == 1);48 try expect(mul[2] == 1);
48 try expectEqualStrings(mul[3], "foo");49 try expectEqualStrings(mul[3], "foo");
4950
50 var t2: T = .{ 2, "bar" };51 var t2: T = .{ 2, "bar" };
51 var cat = t ++ t2;52 _ = &t2;
53 const cat = t ++ t2;
52 try expect(@TypeOf(cat) != T);54 try expect(@TypeOf(cat) != T);
53 try expect(cat.len == 4);55 try expect(cat.len == 4);
54 try expect(cat[2] == 2);56 try expect(cat[2] == 2);
test/behavior/type.zig+3-2
...@@ -410,7 +410,8 @@ test "Type.Union" {...@@ -410,7 +410,8 @@ test "Type.Union" {
410 .decls = &.{},410 .decls = &.{},
411 },411 },
412 });412 });
413 var packed_untagged = PackedUntagged{ .signed = -1 };413 var packed_untagged: PackedUntagged = .{ .signed = -1 };
414 _ = &packed_untagged;
414 try testing.expectEqual(@as(i32, -1), packed_untagged.signed);415 try testing.expectEqual(@as(i32, -1), packed_untagged.signed);
415 try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);416 try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
416417
...@@ -529,7 +530,7 @@ test "reified struct field name from optional payload" {...@@ -529,7 +530,7 @@ test "reified struct field name from optional payload" {
529 .decls = &.{},530 .decls = &.{},
530 .is_tuple = false,531 .is_tuple = false,
531 } });532 } });
532 var t: T = .{ .a = 123 };533 const t: T = .{ .a = 123 };
533 try std.testing.expect(t.a == 123);534 try std.testing.expect(t.a == 123);
534 }535 }
535 }536 }
test/behavior/type_info.zig+1-1
...@@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" {...@@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" {
417 }417 }
418 };418 };
419 comptime var info = @typeInfo(S);419 comptime var info = @typeInfo(S);
420 _ = info;420 _ = &info;
421}421}
422422
423test "type info: vectors" {423test "type info: vectors" {
test/behavior/union.zig+46-5
...@@ -171,6 +171,7 @@ test "constant tagged union with payload" {...@@ -171,6 +171,7 @@ test "constant tagged union with payload" {
171171
172 var empty = TaggedUnionWithPayload{ .Empty = {} };172 var empty = TaggedUnionWithPayload{ .Empty = {} };
173 var full = TaggedUnionWithPayload{ .Full = 13 };173 var full = TaggedUnionWithPayload{ .Full = 13 };
174 _ = .{ &empty, &full };
174 shouldBeEmpty(empty);175 shouldBeEmpty(empty);
175 shouldBeNotEmpty(full);176 shouldBeNotEmpty(full);
176}177}
...@@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 {...@@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 {
254255
255fn testComparison() !void {256fn testComparison() !void {
256 var x = Payload{ .A = 42 };257 var x = Payload{ .A = 42 };
258 _ = &x;
257 try expect(x == .A);259 try expect(x == .A);
258 try expect(x != .B);260 try expect(x != .B);
259 try expect(x != .C);261 try expect(x != .C);
...@@ -288,6 +290,7 @@ test "cast union to tag type of union" {...@@ -288,6 +290,7 @@ test "cast union to tag type of union" {
288290
289fn testCastUnionToTag() !void {291fn testCastUnionToTag() !void {
290 var u = TheUnion{ .B = 1234 };292 var u = TheUnion{ .B = 1234 };
293 _ = &u;
291 try expect(@as(TheTag, u) == TheTag.B);294 try expect(@as(TheTag, u) == TheTag.B);
292}295}
293296
...@@ -303,6 +306,7 @@ test "cast tag type of union to union" {...@@ -303,6 +306,7 @@ test "cast tag type of union to union" {
303 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO306 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
304307
305 var x: Value2 = Letter2.B;308 var x: Value2 = Letter2.B;
309 _ = &x;
306 try expect(@as(Letter2, x) == Letter2.B);310 try expect(@as(Letter2, x) == Letter2.B);
307}311}
308const Letter2 = enum { A, B, C };312const Letter2 = enum { A, B, C };
...@@ -318,6 +322,7 @@ test "implicit cast union to its tag type" {...@@ -318,6 +322,7 @@ test "implicit cast union to its tag type" {
318 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO322 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
319323
320 var x: Value2 = Letter2.B;324 var x: Value2 = Letter2.B;
325 _ = &x;
321 try expect(x == Letter2.B);326 try expect(x == Letter2.B);
322 try giveMeLetterB(x);327 try giveMeLetterB(x);
323}328}
...@@ -356,6 +361,7 @@ test "simple union(enum(u32))" {...@@ -356,6 +361,7 @@ test "simple union(enum(u32))" {
356 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO361 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
357362
358 var x = MultipleChoice.C;363 var x = MultipleChoice.C;
364 _ = &x;
359 try expect(x == MultipleChoice.C);365 try expect(x == MultipleChoice.C);
360 try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60);366 try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60);
361}367}
...@@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" {...@@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" {
420 };426 };
421427
422 var e = Expr{ .Literal = Literal{ .Bool = true } };428 var e = Expr{ .Literal = Literal{ .Bool = true } };
429 _ = &e;
423 const ExprTag = Tag(Expr);430 const ExprTag = Tag(Expr);
424 try comptime expect(Tag(ExprTag) == u0);431 try comptime expect(Tag(ExprTag) == u0);
425 var t = @as(ExprTag, e);432 var t = @as(ExprTag, e);
433 _ = &t;
426 try expect(t == Expr.Literal);434 try expect(t == Expr.Literal);
427}435}
428436
...@@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" {...@@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" {
494 };502 };
495503
496 var v = U{ .A = 532 };504 var v = U{ .A = 532 };
505 _ = &v;
497 try expect(v.A == 532);506 try expect(v.A == 532);
498}507}
499508
...@@ -506,6 +515,7 @@ test "runtime tag name with single field" {...@@ -506,6 +515,7 @@ test "runtime tag name with single field" {
506 };515 };
507516
508 var v = U{ .A = 42 };517 var v = U{ .A = 42 };
518 _ = &v;
509 try expect(std.mem.eql(u8, @tagName(v), "A"));519 try expect(std.mem.eql(u8, @tagName(v), "A"));
510}520}
511521
...@@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci...@@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci
698 };708 };
699709
700 var e = Expr{ .Literal = Literal{ .Bool = true } };710 var e = Expr{ .Literal = Literal{ .Bool = true } };
711 _ = &e;
701 try comptime expect(Tag(ExprTag) == comptime_int);712 try comptime expect(Tag(ExprTag) == comptime_int);
702 comptime var t = @as(ExprTag, e);713 const t = comptime @as(ExprTag, e);
703 try expect(t == Expr.Literal);714 try expect(t == Expr.Literal);
704 try expect(@intFromEnum(t) == 33);715 try expect(@intFromEnum(t) == 33);
705 try comptime expect(@intFromEnum(t) == 33);716 try comptime expect(@intFromEnum(t) == 33);
...@@ -719,6 +730,7 @@ test "@intFromEnum works on unions" {...@@ -719,6 +730,7 @@ test "@intFromEnum works on unions" {
719 const a = Bar{ .A = true };730 const a = Bar{ .A = true };
720 var b = Bar{ .B = undefined };731 var b = Bar{ .B = undefined };
721 var c = Bar.C;732 var c = Bar.C;
733 _ = .{ &b, &c };
722 try expect(@intFromEnum(a) == 0);734 try expect(@intFromEnum(a) == 0);
723 try expect(@intFromEnum(b) == 1);735 try expect(@intFromEnum(b) == 1);
724 try expect(@intFromEnum(c) == 2);736 try expect(@intFromEnum(c) == 2);
...@@ -800,11 +812,13 @@ test "@unionInit stored to a const" {...@@ -800,11 +812,13 @@ test "@unionInit stored to a const" {
800 fn doTheTest() !void {812 fn doTheTest() !void {
801 {813 {
802 var t = true;814 var t = true;
815 _ = &t;
803 const u = @unionInit(U, "boolean", t);816 const u = @unionInit(U, "boolean", t);
804 try expect(u.boolean);817 try expect(u.boolean);
805 }818 }
806 {819 {
807 var byte: u8 = 69;820 var byte: u8 = 69;
821 _ = &byte;
808 const u = @unionInit(U, "byte", byte);822 const u = @unionInit(U, "byte", byte);
809 try expect(u.byte == 69);823 try expect(u.byte == 69);
810 }824 }
...@@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" {...@@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" {
849 };863 };
850864
851 var value: UnionInitEnum = undefined;865 var value: UnionInitEnum = undefined;
852 var value_ptr = &value;866 const value_ptr = &value;
853867
854 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);868 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);
855 try expect(value.Boolean == true);869 try expect(value.Boolean == true);
...@@ -906,7 +920,8 @@ test "anonymous union literal syntax" {...@@ -906,7 +920,8 @@ test "anonymous union literal syntax" {
906920
907 fn doTheTest() !void {921 fn doTheTest() !void {
908 var i: Number = .{ .int = 42 };922 var i: Number = .{ .int = 42 };
909 var f = makeNumber();923 _ = &i;
924 const f = makeNumber();
910 try expect(i.int == 42);925 try expect(i.int == 42);
911 try expect(f.float == 12.34);926 try expect(f.float == 12.34);
912 }927 }
...@@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" {...@@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" {
934949
935 fn doTheTest() !void {950 fn doTheTest() !void {
936 var x: ArchTag = getArch1();951 var x: ArchTag = getArch1();
952 _ = &x;
937 try expect(x == .One);953 try expect(x == .One);
938954
939 var y: ArchTag = getArch2();955 var y: ArchTag = getArch2();
956 _ = &y;
940 try expect(y == .Two);957 try expect(y == .Two);
941 }958 }
942959
...@@ -965,14 +982,17 @@ test "cast from anonymous struct to union" {...@@ -965,14 +982,17 @@ test "cast from anonymous struct to union" {
965 };982 };
966 fn doTheTest() !void {983 fn doTheTest() !void {
967 var y: u32 = 42;984 var y: u32 = 42;
985 _ = &y;
968 const t0 = .{ .A = 123 };986 const t0 = .{ .A = 123 };
969 const t1 = .{ .B = "foo" };987 const t1 = .{ .B = "foo" };
970 const t2 = .{ .C = {} };988 const t2 = .{ .C = {} };
971 const t3 = .{ .A = y };989 const t3 = .{ .A = y };
972 const x0: U = t0;990 const x0: U = t0;
973 var x1: U = t1;991 var x1: U = t1;
992 _ = &x1;
974 const x2: U = t2;993 const x2: U = t2;
975 var x3: U = t3;994 var x3: U = t3;
995 _ = &x3;
976 try expect(x0.A == 123);996 try expect(x0.A == 123);
977 try expect(std.mem.eql(u8, x1.B, "foo"));997 try expect(std.mem.eql(u8, x1.B, "foo"));
978 try expect(x2 == .C);998 try expect(x2 == .C);
...@@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" {...@@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" {
996 };1016 };
997 fn doTheTest() !void {1017 fn doTheTest() !void {
998 var y: u32 = 42;1018 var y: u32 = 42;
1019 _ = &y;
999 const t0 = &.{ .A = 123 };1020 const t0 = &.{ .A = 123 };
1000 const t1 = &.{ .B = "foo" };1021 const t1 = &.{ .B = "foo" };
1001 const t2 = &.{ .C = {} };1022 const t2 = &.{ .C = {} };
1002 const t3 = &.{ .A = y };1023 const t3 = &.{ .A = y };
1003 const x0: *const U = t0;1024 const x0: *const U = t0;
1004 var x1: *const U = t1;1025 var x1: *const U = t1;
1026 _ = &x1;
1005 const x2: *const U = t2;1027 const x2: *const U = t2;
1006 var x3: *const U = t3;1028 var x3: *const U = t3;
1029 _ = &x3;
1007 try expect(x0.A == 123);1030 try expect(x0.A == 123);
1008 try expect(std.mem.eql(u8, x1.B, "foo"));1031 try expect(std.mem.eql(u8, x1.B, "foo"));
1009 try expect(x2.* == .C);1032 try expect(x2.* == .C);
...@@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" {...@@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" {
1031 };1054 };
1032 fn doTheTest() !void {1055 fn doTheTest() !void {
1033 var a = U{ .a = 2 };1056 var a = U{ .a = 2 };
1057 _ = &a;
1034 switch (a) {1058 switch (a) {
1035 .a => |val| try expect(val == 2),1059 .a => |val| try expect(val == 2),
1036 .b => return error.Fail,1060 .b => return error.Fail,
...@@ -1055,11 +1079,13 @@ test "containers with single-field enums" {...@@ -1055,11 +1079,13 @@ test "containers with single-field enums" {
1055 fn doTheTest() !void {1079 fn doTheTest() !void {
1056 var array1 = [1]A{A{ .f1 = {} }};1080 var array1 = [1]A{A{ .f1 = {} }};
1057 var array2 = [1]B{B{ .f1 = {} }};1081 var array2 = [1]B{B{ .f1 = {} }};
1082 _ = .{ &array1, &array2 };
1058 try expect(array1[0] == .f1);1083 try expect(array1[0] == .f1);
1059 try expect(array2[0] == .f1);1084 try expect(array2[0] == .f1);
10601085
1061 var struct1 = C{ .a = A{ .f1 = {} } };1086 var struct1 = C{ .a = A{ .f1 = {} } };
1062 var struct2 = D{ .a = B{ .f1 = {} } };1087 var struct2 = D{ .a = B{ .f1 = {} } };
1088 _ = .{ &struct1, &struct2 };
1063 try expect(struct1.a == .f1);1089 try expect(struct1.a == .f1);
1064 try expect(struct2.a == .f1);1090 try expect(struct2.a == .f1);
1065 }1091 }
...@@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" {...@@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" {
10921118
1093 fn doTheTest() !void {1119 fn doTheTest() !void {
1094 var data: Data = .{ .no_op = {} };1120 var data: Data = .{ .no_op = {} };
1095 _ = data;1121 _ = &data;
1096 var o = Data.decode(&[_]u8{});1122 var o = Data.decode(&[_]u8{});
1123 _ = &o;
1097 try expectEqual(Type.no_op, o);1124 try expectEqual(Type.no_op, o);
1098 }1125 }
1099 };1126 };
...@@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" {...@@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" {
1156 }1183 }
1157 };1184 };
1158 var a: u32 = 1;1185 var a: u32 = 1;
1186 _ = &a;
1159 U.foo(U{ .a = a });1187 U.foo(U{ .a = a });
1160}1188}
11611189
...@@ -1174,6 +1202,7 @@ test "union with a large struct field" {...@@ -1174,6 +1202,7 @@ test "union with a large struct field" {
1174 fn foo(_: @This()) void {}1202 fn foo(_: @This()) void {}
1175 };1203 };
1176 var s: S = undefined;1204 var s: S = undefined;
1205 _ = &s;
1177 U.foo(U{ .s = s });1206 U.foo(U{ .s = s });
1178}1207}
11791208
...@@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" {...@@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" {
1207 }1236 }
1208 };1237 };
1209 var b: u32 = 1;1238 var b: u32 = 1;
1239 _ = &b;
1210 try (U{ .b = b }).doTheTest();1240 try (U{ .b = b }).doTheTest();
1211}1241}
12121242
...@@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" {...@@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" {
1226 un: [110]u8,1256 un: [110]u8,
1227 };1257 };
1228 var a: ?U = .{ .un = [_]u8{0} ** 110 };1258 var a: ?U = .{ .un = [_]u8{0} ** 110 };
1259 _ = &a;
1229 try expect(a != null);1260 try expect(a != null);
1230}1261}
12311262
...@@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" {...@@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" {
12461277
1247 fn bar(arg_u: U) callconv(.C) U {1278 fn bar(arg_u: U) callconv(.C) U {
1248 var u = arg_u;1279 var u = arg_u;
1280 _ = &u;
1249 return u;1281 return u;
1250 }1282 }
1251 };1283 };
...@@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" {...@@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" {
1324 a: usize,1356 a: usize,
1325 };1357 };
1326 var i: isize = -1;1358 var i: isize = -1;
1359 _ = &i;
1327 var u = @unionInit(U, "b", i);1360 var u = @unionInit(U, "b", i);
1328 {1361 {
1329 var a = u.b;1362 var a = u.b;
1363 _ = &a;
1330 try expect(a == i);1364 try expect(a == i);
1331 }1365 }
1332 {1366 {
1333 var a = &u.b;1367 var a = &u.b;
1368 _ = &a;
1334 try expect(a.* == i);1369 try expect(a.* == i);
1335 }1370 }
1336 try expect(@intFromEnum(u) == 255);1371 try expect(@intFromEnum(u) == 255);
...@@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" {...@@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" {
1508 b: u8,1543 b: u8,
15091544
1510 fn doTest(c: bool) !void {1545 fn doTest(c: bool) !void {
1511 var u = if (c) .a else @This(){ .b = 0 };1546 const u = if (c) .a else @This(){ .b = 0 };
1512 try expect(u == .a);1547 try expect(u == .a);
1513 }1548 }
1514 };1549 };
...@@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" {...@@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" {
1947 };1982 };
19481983
1949 var s: S = .{};1984 var s: S = .{};
1985 _ = &s;
1950 try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa));1986 try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa));
1951 try expect(s.u.b == if (endian == .little) 0xaa else 0xdd);1987 try expect(s.u.b == if (endian == .little) 0xaa else 0xdd);
1952}1988}
...@@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" {...@@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" {
1966 };2002 };
19672003
1968 var u: U = reinterpreted;2004 var u: U = reinterpreted;
2005 _ = &u;
1969 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));2006 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));
1970 try expect(u.b == 0xaa);2007 try expect(u.b == 0xaa);
1971}2008}
...@@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" {...@@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" {
1985 };2022 };
19862023
1987 var u: U = reinterpreted;2024 var u: U = reinterpreted;
2025 _ = &u;
1988 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));2026 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));
1989 try expect(u.b == if (endian == .little) 0xaa else 0xdd);2027 try expect(u.b == if (endian == .little) 0xaa else 0xdd);
1990}2028}
...@@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" {...@@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" {
2018 };2056 };
20192057
2020 var x: usize = 42;2058 var x: usize = 42;
2059 _ = &x;
2021 try S.taggedUnion(.{ .x = x });2060 try S.taggedUnion(.{ .x = x });
2022 try S.untaggedUnion(.{ .x = x });2061 try S.untaggedUnion(.{ .x = x });
2023 try S.externUnion(.{ .x = x });2062 try S.externUnion(.{ .x = x });
...@@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" {...@@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" {
2039 };2078 };
2040 };2079 };
2041 var outer: S.UnionOuter = .{};2080 var outer: S.UnionOuter = .{};
2081 _ = &outer;
2042 try expect(outer.u.outer == null);2082 try expect(outer.u.outer == null);
2043 try expect(outer.u.inner == null);2083 try expect(outer.u.inner == null);
2044}2084}
...@@ -2057,5 +2097,6 @@ test "pass nested union with rls" {...@@ -2057,5 +2097,6 @@ test "pass nested union with rls" {
2057 };2097 };
20582098
2059 var c: u7 = 32;2099 var c: u7 = 32;
2100 _ = &c;
2060 try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } }));2101 try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } }));
2061}2102}
test/behavior/var_args.zig+1
...@@ -147,6 +147,7 @@ test "simple variadic function" {...@@ -147,6 +147,7 @@ test "simple variadic function" {
147 var runtime: bool = true;147 var runtime: bool = true;
148 var a: i32 = 1;148 var a: i32 = 1;
149 var b: i32 = 2;149 var b: i32 = 2;
150 _ = .{ &runtime, &a, &b };
150 try expect(1 == S.add(1, if (runtime) a else b));151 try expect(1 == S.add(1, if (runtime) a else b));
151 }152 }
152}153}
test/behavior/vector.zig+99-55
...@@ -40,6 +40,7 @@ test "vector wrap operators" {...@@ -40,6 +40,7 @@ test "vector wrap operators" {
40 try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));40 try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
41 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };41 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
42 try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));42 try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
43 _ = .{ &v, &x, &z };
43 }44 }
44 };45 };
45 try S.doTheTest();46 try S.doTheTest();
...@@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" {...@@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" {
57 fn doTheTest() !void {58 fn doTheTest() !void {
58 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };59 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
59 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };60 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
61 _ = .{ &v, &x };
60 try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));62 try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
61 try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));63 try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
62 try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));64 try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
...@@ -81,6 +83,7 @@ test "vector int operators" {...@@ -81,6 +83,7 @@ test "vector int operators" {
81 fn doTheTest() !void {83 fn doTheTest() !void {
82 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };84 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
83 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };85 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
86 _ = .{ &v, &x };
84 try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));87 try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
85 try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));88 try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
86 try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));89 try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
...@@ -105,6 +108,7 @@ test "vector float operators" {...@@ -105,6 +108,7 @@ test "vector float operators" {
105 fn doTheTest() !void {108 fn doTheTest() !void {
106 var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 };109 var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 };
107 var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 };110 var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 };
111 _ = .{ &v, &x };
108 try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 }));112 try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 }));
109 try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 }));113 try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 }));
110 try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 }));114 try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 }));
...@@ -126,6 +130,7 @@ test "vector bit operators" {...@@ -126,6 +130,7 @@ test "vector bit operators" {
126 fn doTheTest() !void {130 fn doTheTest() !void {
127 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };131 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
128 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };132 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
133 _ = .{ &v, &x };
129 try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));134 try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
130 try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));135 try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
131 try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));136 try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
...@@ -143,6 +148,7 @@ test "implicit cast vector to array" {...@@ -143,6 +148,7 @@ test "implicit cast vector to array" {
143 const S = struct {148 const S = struct {
144 fn doTheTest() !void {149 fn doTheTest() !void {
145 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };150 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
151 _ = &a;
146 var result_array: [4]i32 = a;152 var result_array: [4]i32 = a;
147 result_array = a;153 result_array = a;
148 try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));154 try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
...@@ -160,8 +166,9 @@ test "array to vector" {...@@ -160,8 +166,9 @@ test "array to vector" {
160 const S = struct {166 const S = struct {
161 fn doTheTest() !void {167 fn doTheTest() !void {
162 var foo: f32 = 3.14;168 var foo: f32 = 3.14;
163 var arr = [4]f32{ foo, 1.5, 0.0, 0.0 };169 _ = &foo;
164 var vec: @Vector(4, f32) = arr;170 const arr = [4]f32{ foo, 1.5, 0.0, 0.0 };
171 const vec: @Vector(4, f32) = arr;
165 try expect(mem.eql(f32, &@as([4]f32, vec), &arr));172 try expect(mem.eql(f32, &@as([4]f32, vec), &arr));
166 }173 }
167 };174 };
...@@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" {...@@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" {
180 const S = struct {187 const S = struct {
181 fn doTheTest() !void {188 fn doTheTest() !void {
182 var foo1: i48 = 124578;189 var foo1: i48 = 124578;
183 var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 };190 _ = &foo1;
184 var arr1: [2]i48 = vec1;191 const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 };
192 const arr1: [2]i48 = vec1;
185 try expect(vec1[0] == foo1 and vec1[1] == 1);193 try expect(vec1[0] == foo1 and vec1[1] == 1);
186 try expect(arr1[0] == foo1 and arr1[1] == 1);194 try expect(arr1[0] == foo1 and arr1[1] == 1);
187195
188 var foo2: u4 = 5;196 var foo2: u4 = 5;
189 var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 };197 _ = &foo2;
190 var arr2: [2]u4 = vec2;198 const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 };
199 const arr2: [2]u4 = vec2;
191 try expect(vec2[0] == foo2 and vec2[1] == 1);200 try expect(vec2[0] == foo2 and vec2[1] == 1);
192 try expect(arr2[0] == foo2 and arr2[1] == 1);201 try expect(arr2[0] == foo2 and arr2[1] == 1);
193202
194 var foo3: u13 = 13;203 var foo3: u13 = 13;
195 var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 };204 _ = &foo3;
196 var arr3: [3]u13 = vec3;205 const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 };
206 const arr3: [3]u13 = vec3;
197 try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1);207 try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1);
198 try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1);208 try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1);
199209
200 var arr4 = [4:0]u24{ foo3, foo2, 0, 1 };210 const arr4 = [4:0]u24{ foo3, foo2, 0, 1 };
201 var vec4: @Vector(4, u24) = arr4;211 const vec4: @Vector(4, u24) = arr4;
202 try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1);212 try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1);
203 }213 }
204 };214 };
...@@ -217,8 +227,9 @@ test "array to vector with element type coercion" {...@@ -217,8 +227,9 @@ test "array to vector with element type coercion" {
217 const S = struct {227 const S = struct {
218 fn doTheTest() !void {228 fn doTheTest() !void {
219 var foo: f16 = 3.14;229 var foo: f16 = 3.14;
220 var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 };230 _ = &foo;
221 var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 };231 const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 };
232 const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 };
222 try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32));233 try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32));
223 }234 }
224 };235 };
...@@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" {...@@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" {
237 var b: @Vector(2, u8) = .{ 1, 2 };248 var b: @Vector(2, u8) = .{ 1, 2 };
238 var a: @Vector(2, u16) = .{ 2, 1 };249 var a: @Vector(2, u16) = .{ 2, 1 };
239 var t: bool = true;250 var t: bool = true;
240 var c = if (t) a else b;251 _ = .{ &a, &b, &t };
252 const c = if (t) a else b;
241 try std.testing.expect(@TypeOf(c) == @Vector(2, u16));253 try std.testing.expect(@TypeOf(c) == @Vector(2, u16));
242 }254 }
243 };255 };
...@@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" {...@@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" {
285 fn doTheTest() !void {297 fn doTheTest() !void {
286 {298 {
287 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };299 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
288 var x: [4]u3 = v;300 _ = &v;
301 const x: [4]u3 = v;
289 try expect(mem.eql(u3, &x, &@as([4]u3, v)));302 try expect(mem.eql(u3, &x, &@as([4]u3, v)));
290 }303 }
291 {304 {
292 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };305 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
293 var x: [4]u2 = v;306 _ = &v;
307 const x: [4]u2 = v;
294 try expect(mem.eql(u2, &x, &@as([4]u2, v)));308 try expect(mem.eql(u2, &x, &@as([4]u2, v)));
295 }309 }
296 {310 {
297 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };311 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
298 var x: [4]u1 = v;312 _ = &v;
313 const x: [4]u1 = v;
299 try expect(mem.eql(u1, &x, &@as([4]u1, v)));314 try expect(mem.eql(u1, &x, &@as([4]u1, v)));
300 }315 }
301 {316 {
302 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };317 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
303 var x: [4]bool = v;318 _ = &v;
319 const x: [4]bool = v;
304 try expect(mem.eql(bool, &x, &@as([4]bool, v)));320 try expect(mem.eql(bool, &x, &@as([4]bool, v)));
305 }321 }
306 }322 }
...@@ -327,7 +343,8 @@ test "vector @splat" {...@@ -327,7 +343,8 @@ test "vector @splat" {
327 fn testForT(comptime N: comptime_int, v: anytype) !void {343 fn testForT(comptime N: comptime_int, v: anytype) !void {
328 const T = @TypeOf(v);344 const T = @TypeOf(v);
329 var vec: @Vector(N, T) = @splat(v);345 var vec: @Vector(N, T) = @splat(v);
330 var as_array = @as([N]T, vec);346 _ = &vec;
347 const as_array = @as([N]T, vec);
331 for (as_array) |elem| try expect(v == elem);348 for (as_array) |elem| try expect(v == elem);
332 }349 }
333 fn doTheTest() !void {350 fn doTheTest() !void {
...@@ -412,6 +429,7 @@ test "load vector elements via runtime index" {...@@ -412,6 +429,7 @@ test "load vector elements via runtime index" {
412 const S = struct {429 const S = struct {
413 fn doTheTest() !void {430 fn doTheTest() !void {
414 var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };431 var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
432 _ = &v;
415 var i: u32 = 0;433 var i: u32 = 0;
416 try expect(v[i] == 1);434 try expect(v[i] == 1);
417 i += 1;435 i += 1;
...@@ -461,7 +479,7 @@ test "initialize vector which is a struct field" {...@@ -461,7 +479,7 @@ test "initialize vector which is a struct field" {
461 var foo = Vec4Obj{479 var foo = Vec4Obj{
462 .data = [_]f32{ 1, 2, 3, 4 },480 .data = [_]f32{ 1, 2, 3, 4 },
463 };481 };
464 _ = foo;482 _ = &foo;
465 }483 }
466 };484 };
467 try S.doTheTest();485 try S.doTheTest();
...@@ -481,6 +499,7 @@ test "vector comparison operators" {...@@ -481,6 +499,7 @@ test "vector comparison operators" {
481 const V = @Vector(4, bool);499 const V = @Vector(4, bool);
482 var v1: V = [_]bool{ true, false, true, false };500 var v1: V = [_]bool{ true, false, true, false };
483 var v2: V = [_]bool{ false, true, false, true };501 var v2: V = [_]bool{ false, true, false, true };
502 _ = .{ &v1, &v2 };
484 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1)));503 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1)));
485 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2)));504 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2)));
486 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2)));505 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2)));
...@@ -491,6 +510,7 @@ test "vector comparison operators" {...@@ -491,6 +510,7 @@ test "vector comparison operators" {
491 var v1: @Vector(4, u32) = @splat(0xc0ffeeee);510 var v1: @Vector(4, u32) = @splat(0xc0ffeeee);
492 var v2: @Vector(4, c_uint) = v1;511 var v2: @Vector(4, c_uint) = v1;
493 var v3: @Vector(4, u32) = @splat(0xdeadbeef);512 var v3: @Vector(4, u32) = @splat(0xdeadbeef);
513 _ = .{ &v1, &v2, &v3 };
494 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2)));514 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2)));
495 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3)));515 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3)));
496 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3)));516 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3)));
...@@ -499,6 +519,7 @@ test "vector comparison operators" {...@@ -499,6 +519,7 @@ test "vector comparison operators" {
499 {519 {
500 // Comptime-known LHS/RHS520 // Comptime-known LHS/RHS
501 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };521 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
522 _ = &v1;
502 const v2: @Vector(4, u32) = @splat(2);523 const v2: @Vector(4, u32) = @splat(2);
503 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };524 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
504 try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2)));525 try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2)));
...@@ -604,7 +625,7 @@ test "vector bitwise not operator" {...@@ -604,7 +625,7 @@ test "vector bitwise not operator" {
604625
605 const S = struct {626 const S = struct {
606 fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void {627 fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void {
607 var y = ~x;628 const y = ~x;
608 for (@as([4]T, y), 0..) |v, i| {629 for (@as([4]T, y), 0..) |v, i| {
609 try expect(~x[i] == v);630 try expect(~x[i] == v);
610 }631 }
...@@ -640,14 +661,14 @@ test "vector shift operators" {...@@ -640,14 +661,14 @@ test "vector shift operators" {
640 const TX = @typeInfo(@TypeOf(x)).Array.child;661 const TX = @typeInfo(@TypeOf(x)).Array.child;
641 const TY = @typeInfo(@TypeOf(y)).Array.child;662 const TY = @typeInfo(@TypeOf(y)).Array.child;
642663
643 var xv = @as(@Vector(N, TX), x);664 const xv = @as(@Vector(N, TX), x);
644 var yv = @as(@Vector(N, TY), y);665 const yv = @as(@Vector(N, TY), y);
645666
646 var z0 = xv >> yv;667 const z0 = xv >> yv;
647 for (@as([N]TX, z0), 0..) |v, i| {668 for (@as([N]TX, z0), 0..) |v, i| {
648 try expect(x[i] >> y[i] == v);669 try expect(x[i] >> y[i] == v);
649 }670 }
650 var z1 = xv << yv;671 const z1 = xv << yv;
651 for (@as([N]TX, z1), 0..) |v, i| {672 for (@as([N]TX, z1), 0..) |v, i| {
652 try expect(x[i] << y[i] == v);673 try expect(x[i] << y[i] == v);
653 }674 }
...@@ -657,10 +678,10 @@ test "vector shift operators" {...@@ -657,10 +678,10 @@ test "vector shift operators" {
657 const TX = @typeInfo(@TypeOf(x)).Array.child;678 const TX = @typeInfo(@TypeOf(x)).Array.child;
658 const TY = @typeInfo(@TypeOf(y)).Array.child;679 const TY = @typeInfo(@TypeOf(y)).Array.child;
659680
660 var xv = @as(@Vector(N, TX), x);681 const xv = @as(@Vector(N, TX), x);
661 var yv = @as(@Vector(N, TY), y);682 const yv = @as(@Vector(N, TY), y);
662683
663 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);684 const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
664 for (@as([N]TX, z), 0..) |v, i| {685 for (@as([N]TX, z), 0..) |v, i| {
665 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];686 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
666 try expect(check == v);687 try expect(check == v);
...@@ -734,7 +755,7 @@ test "vector reduce operation" {...@@ -734,7 +755,7 @@ test "vector reduce operation" {
734 const N = @typeInfo(@TypeOf(x)).Array.len;755 const N = @typeInfo(@TypeOf(x)).Array.len;
735 const TX = @typeInfo(@TypeOf(x)).Array.child;756 const TX = @typeInfo(@TypeOf(x)).Array.child;
736757
737 var r = @reduce(op, @as(@Vector(N, TX), x));758 const r = @reduce(op, @as(@Vector(N, TX), x));
738 switch (@typeInfo(TX)) {759 switch (@typeInfo(TX)) {
739 .Int, .Bool => try expect(expected == r),760 .Int, .Bool => try expect(expected == r),
740 .Float => {761 .Float => {
...@@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" {...@@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" {
892 const __v4hi = @Vector(4, i16);913 const __v4hi = @Vector(4, i16);
893 var v4_a = __v4hi{ 0, 0, 0, 0 };914 var v4_a = __v4hi{ 0, 0, 0, 0 };
894 var v4_b = __v4hi{ 0, 0, 0, 0 };915 var v4_b = __v4hi{ 0, 0, 0, 0 };
895 var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){916 _ = .{ &v4_a, &v4_b };
917 const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){
896 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),918 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
897 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),919 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
898 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),920 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
...@@ -915,7 +937,8 @@ test "saturating add" {...@@ -915,7 +937,8 @@ test "saturating add" {
915 const u8x3 = @Vector(3, u8);937 const u8x3 = @Vector(3, u8);
916 var lhs = u8x3{ 255, 254, 1 };938 var lhs = u8x3{ 255, 254, 1 };
917 var rhs = u8x3{ 1, 2, 255 };939 var rhs = u8x3{ 1, 2, 255 };
918 var result = lhs +| rhs;940 _ = .{ &lhs, &rhs };
941 const result = lhs +| rhs;
919 const expected = u8x3{ 255, 255, 255 };942 const expected = u8x3{ 255, 255, 255 };
920 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));943 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
921 }944 }
...@@ -923,7 +946,8 @@ test "saturating add" {...@@ -923,7 +946,8 @@ test "saturating add" {
923 const i8x3 = @Vector(3, i8);946 const i8x3 = @Vector(3, i8);
924 var lhs = i8x3{ 127, 126, 1 };947 var lhs = i8x3{ 127, 126, 1 };
925 var rhs = i8x3{ 1, 2, 127 };948 var rhs = i8x3{ 1, 2, 127 };
926 var result = lhs +| rhs;949 _ = .{ &lhs, &rhs };
950 const result = lhs +| rhs;
927 const expected = i8x3{ 127, 127, 127 };951 const expected = i8x3{ 127, 127, 127 };
928 try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result)));952 try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result)));
929 }953 }
...@@ -947,7 +971,8 @@ test "saturating subtraction" {...@@ -947,7 +971,8 @@ test "saturating subtraction" {
947 const u8x3 = @Vector(3, u8);971 const u8x3 = @Vector(3, u8);
948 var lhs = u8x3{ 0, 0, 0 };972 var lhs = u8x3{ 0, 0, 0 };
949 var rhs = u8x3{ 255, 255, 255 };973 var rhs = u8x3{ 255, 255, 255 };
950 var result = lhs -| rhs;974 _ = .{ &lhs, &rhs };
975 const result = lhs -| rhs;
951 const expected = u8x3{ 0, 0, 0 };976 const expected = u8x3{ 0, 0, 0 };
952 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));977 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
953 }978 }
...@@ -973,7 +998,8 @@ test "saturating multiplication" {...@@ -973,7 +998,8 @@ test "saturating multiplication" {
973 const u8x3 = @Vector(3, u8);998 const u8x3 = @Vector(3, u8);
974 var lhs = u8x3{ 2, 2, 2 };999 var lhs = u8x3{ 2, 2, 2 };
975 var rhs = u8x3{ 255, 255, 255 };1000 var rhs = u8x3{ 255, 255, 255 };
976 var result = lhs *| rhs;1001 _ = .{ &lhs, &rhs };
1002 const result = lhs *| rhs;
977 const expected = u8x3{ 255, 255, 255 };1003 const expected = u8x3{ 255, 255, 255 };
978 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));1004 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
979 }1005 }
...@@ -997,7 +1023,8 @@ test "saturating shift-left" {...@@ -997,7 +1023,8 @@ test "saturating shift-left" {
997 const u8x3 = @Vector(3, u8);1023 const u8x3 = @Vector(3, u8);
998 var lhs = u8x3{ 1, 1, 1 };1024 var lhs = u8x3{ 1, 1, 1 };
999 var rhs = u8x3{ 255, 255, 255 };1025 var rhs = u8x3{ 255, 255, 255 };
1000 var result = lhs <<| rhs;1026 _ = .{ &lhs, &rhs };
1027 const result = lhs <<| rhs;
1001 const expected = u8x3{ 255, 255, 255 };1028 const expected = u8x3{ 255, 255, 255 };
1002 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));1029 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
1003 }1030 }
...@@ -1040,29 +1067,33 @@ test "@addWithOverflow" {...@@ -1040,29 +1067,33 @@ test "@addWithOverflow" {
1040 {1067 {
1041 var lhs = @Vector(4, u8){ 250, 250, 250, 250 };1068 var lhs = @Vector(4, u8){ 250, 250, 250, 250 };
1042 var rhs = @Vector(4, u8){ 0, 5, 6, 10 };1069 var rhs = @Vector(4, u8){ 0, 5, 6, 10 };
1043 var overflow = @addWithOverflow(lhs, rhs)[1];1070 _ = .{ &lhs, &rhs };
1044 var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };1071 const overflow = @addWithOverflow(lhs, rhs)[1];
1072 const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
1045 try expectEqual(expected, overflow);1073 try expectEqual(expected, overflow);
1046 }1074 }
1047 {1075 {
1048 var lhs = @Vector(4, i8){ -125, -125, 125, 125 };1076 var lhs = @Vector(4, i8){ -125, -125, 125, 125 };
1049 var rhs = @Vector(4, i8){ -3, -4, 2, 3 };1077 var rhs = @Vector(4, i8){ -3, -4, 2, 3 };
1050 var overflow = @addWithOverflow(lhs, rhs)[1];1078 _ = .{ &lhs, &rhs };
1051 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };1079 const overflow = @addWithOverflow(lhs, rhs)[1];
1080 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1052 try expectEqual(expected, overflow);1081 try expectEqual(expected, overflow);
1053 }1082 }
1054 {1083 {
1055 var lhs = @Vector(4, u1){ 0, 0, 1, 1 };1084 var lhs = @Vector(4, u1){ 0, 0, 1, 1 };
1056 var rhs = @Vector(4, u1){ 0, 1, 0, 1 };1085 var rhs = @Vector(4, u1){ 0, 1, 0, 1 };
1057 var overflow = @addWithOverflow(lhs, rhs)[1];1086 _ = .{ &lhs, &rhs };
1058 var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 };1087 const overflow = @addWithOverflow(lhs, rhs)[1];
1088 const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 };
1059 try expectEqual(expected, overflow);1089 try expectEqual(expected, overflow);
1060 }1090 }
1061 {1091 {
1062 var lhs = @Vector(4, u0){ 0, 0, 0, 0 };1092 var lhs = @Vector(4, u0){ 0, 0, 0, 0 };
1063 var rhs = @Vector(4, u0){ 0, 0, 0, 0 };1093 var rhs = @Vector(4, u0){ 0, 0, 0, 0 };
1064 var overflow = @addWithOverflow(lhs, rhs)[1];1094 _ = .{ &lhs, &rhs };
1065 var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 };1095 const overflow = @addWithOverflow(lhs, rhs)[1];
1096 const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 };
1066 try expectEqual(expected, overflow);1097 try expectEqual(expected, overflow);
1067 }1098 }
1068 }1099 }
...@@ -1084,15 +1115,17 @@ test "@subWithOverflow" {...@@ -1084,15 +1115,17 @@ test "@subWithOverflow" {
1084 {1115 {
1085 var lhs = @Vector(2, u8){ 5, 5 };1116 var lhs = @Vector(2, u8){ 5, 5 };
1086 var rhs = @Vector(2, u8){ 5, 6 };1117 var rhs = @Vector(2, u8){ 5, 6 };
1087 var overflow = @subWithOverflow(lhs, rhs)[1];1118 _ = .{ &lhs, &rhs };
1088 var expected: @Vector(2, u1) = .{ 0, 1 };1119 const overflow = @subWithOverflow(lhs, rhs)[1];
1120 const expected: @Vector(2, u1) = .{ 0, 1 };
1089 try expectEqual(expected, overflow);1121 try expectEqual(expected, overflow);
1090 }1122 }
1091 {1123 {
1092 var lhs = @Vector(4, i8){ -120, -120, 120, 120 };1124 var lhs = @Vector(4, i8){ -120, -120, 120, 120 };
1093 var rhs = @Vector(4, i8){ 8, 9, -7, -8 };1125 var rhs = @Vector(4, i8){ 8, 9, -7, -8 };
1094 var overflow = @subWithOverflow(lhs, rhs)[1];1126 _ = .{ &lhs, &rhs };
1095 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };1127 const overflow = @subWithOverflow(lhs, rhs)[1];
1128 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1096 try expectEqual(expected, overflow);1129 try expectEqual(expected, overflow);
1097 }1130 }
1098 }1131 }
...@@ -1113,8 +1146,9 @@ test "@mulWithOverflow" {...@@ -1113,8 +1146,9 @@ test "@mulWithOverflow" {
1113 fn doTheTest() !void {1146 fn doTheTest() !void {
1114 var lhs = @Vector(4, u8){ 10, 10, 10, 10 };1147 var lhs = @Vector(4, u8){ 10, 10, 10, 10 };
1115 var rhs = @Vector(4, u8){ 25, 26, 0, 30 };1148 var rhs = @Vector(4, u8){ 25, 26, 0, 30 };
1116 var overflow = @mulWithOverflow(lhs, rhs)[1];1149 _ = .{ &lhs, &rhs };
1117 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };1150 const overflow = @mulWithOverflow(lhs, rhs)[1];
1151 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1118 try expectEqual(expected, overflow);1152 try expectEqual(expected, overflow);
1119 }1153 }
1120 };1154 };
...@@ -1134,8 +1168,9 @@ test "@shlWithOverflow" {...@@ -1134,8 +1168,9 @@ test "@shlWithOverflow" {
1134 fn doTheTest() !void {1168 fn doTheTest() !void {
1135 var lhs = @Vector(4, u8){ 0, 1, 8, 255 };1169 var lhs = @Vector(4, u8){ 0, 1, 8, 255 };
1136 var rhs = @Vector(4, u3){ 7, 7, 7, 7 };1170 var rhs = @Vector(4, u3){ 7, 7, 7, 7 };
1137 var overflow = @shlWithOverflow(lhs, rhs)[1];1171 _ = .{ &lhs, &rhs };
1138 var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };1172 const overflow = @shlWithOverflow(lhs, rhs)[1];
1173 const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
1139 try expectEqual(expected, overflow);1174 try expectEqual(expected, overflow);
1140 }1175 }
1141 };1176 };
...@@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" {...@@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" {
1161 @Vector(2, u8){ 0, 1 },1196 @Vector(2, u8){ 0, 1 },
1162 @Vector(2, u8){ 2, 3 },1197 @Vector(2, u8){ 2, 3 },
1163 };1198 };
1164 var a: []const @Vector(2, u8) = &small_bases;1199 const a: []const @Vector(2, u8) = &small_bases;
1165 var a4 = a[1][1];1200 const a4 = a[1][1];
1166 try expect(a4 == 3);1201 try expect(a4 == 3);
1167}1202}
11681203
...@@ -1183,6 +1218,7 @@ test "array of vectors is copied" {...@@ -1183,6 +1218,7 @@ test "array of vectors is copied" {
1183 Vec3{ -345, -311, 381 },1218 Vec3{ -345, -311, 381 },
1184 Vec3{ -661, -816, -575 },1219 Vec3{ -661, -816, -575 },
1185 };1220 };
1221 _ = &points;
1186 var points2: [20]Vec3 = undefined;1222 var points2: [20]Vec3 = undefined;
1187 points2[0..points.len].* = points;1223 points2[0..points.len].* = points;
1188 try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 });1224 try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 });
...@@ -1244,6 +1280,7 @@ test "zero multiplicand" {...@@ -1244,6 +1280,7 @@ test "zero multiplicand" {
12441280
1245 const zeros = @Vector(2, u32){ 0.0, 0.0 };1281 const zeros = @Vector(2, u32){ 0.0, 0.0 };
1246 var ones = @Vector(2, u32){ 1.0, 1.0 };1282 var ones = @Vector(2, u32){ 1.0, 1.0 };
1283 _ = &ones;
12471284
1248 _ = (ones * zeros)[0];1285 _ = (ones * zeros)[0];
1249 _ = (zeros * zeros)[0];1286 _ = (zeros * zeros)[0];
...@@ -1266,6 +1303,7 @@ test "@intCast to u0" {...@@ -1266,6 +1303,7 @@ test "@intCast to u0" {
1266 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1303 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12671304
1268 var zeros = @Vector(2, u32){ 0, 0 };1305 var zeros = @Vector(2, u32){ 0, 0 };
1306 _ = &zeros;
1269 const casted = @as(@Vector(2, u0), @intCast(zeros));1307 const casted = @as(@Vector(2, u0), @intCast(zeros));
12701308
1271 _ = casted[0];1309 _ = casted[0];
...@@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" {...@@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" {
1292 const mask = [5]i32{ -1, 0, 1, 2, 3 };1330 const mask = [5]i32{ -1, 0, 1, 2, 3 };
12931331
1294 var a = [5]u32{ 3, 5, 7, 9, 0 };1332 var a = [5]u32{ 3, 5, 7, 9, 0 };
1295 var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask);1333 _ = &a;
1334 const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask);
1296 try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b);1335 try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b);
1297}1336}
12981337
...@@ -1320,6 +1359,7 @@ test "store packed vector element" {...@@ -1320,6 +1359,7 @@ test "store packed vector element" {
1320 var v = @Vector(4, u1){ 1, 1, 1, 1 };1359 var v = @Vector(4, u1){ 1, 1, 1, 1 };
1321 try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v);1360 try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v);
1322 var index: usize = 0;1361 var index: usize = 0;
1362 _ = &index;
1323 v[index] = 0;1363 v[index] = 0;
1324 try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v);1364 try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v);
1325}1365}
...@@ -1337,6 +1377,7 @@ test "store to vector in slice" {...@@ -1337,6 +1377,7 @@ test "store to vector in slice" {
1337 };1377 };
1338 var s: []@Vector(3, f32) = &v;1378 var s: []@Vector(3, f32) = &v;
1339 var i: usize = 1;1379 var i: usize = 1;
1380 _ = &i;
1340 s[i] = s[0];1381 s[i] = s[0];
1341 try expectEqual(v[1], v[0]);1382 try expectEqual(v[1], v[0]);
1342}1383}
...@@ -1378,6 +1419,7 @@ test "store vector with memset" {...@@ -1378,6 +1419,7 @@ test "store vector with memset" {
1378 var kc = @Vector(2, i4){ 2, 3 };1419 var kc = @Vector(2, i4){ 2, 3 };
1379 var kd = @Vector(2, u8){ 4, 5 };1420 var kd = @Vector(2, u8){ 4, 5 };
1380 var ke = @Vector(2, i9){ 6, 7 };1421 var ke = @Vector(2, i9){ 6, 7 };
1422 _ = .{ &ka, &kb, &kc, &kd, &ke };
1381 @memset(&a, ka);1423 @memset(&a, ka);
1382 @memset(&b, kb);1424 @memset(&b, kb);
1383 @memset(&c, kc);1425 @memset(&c, kc);
...@@ -1410,6 +1452,7 @@ test "compare vectors with different element types" {...@@ -1410,6 +1452,7 @@ test "compare vectors with different element types" {
14101452
1411 var a: @Vector(2, u8) = .{ 1, 2 };1453 var a: @Vector(2, u8) = .{ 1, 2 };
1412 var b: @Vector(2, u9) = .{ 3, 0 };1454 var b: @Vector(2, u9) = .{ 3, 0 };
1455 _ = .{ &a, &b };
1413 try expectEqual(@Vector(2, bool){ true, false }, a < b);1456 try expectEqual(@Vector(2, bool){ true, false }, a < b);
1414}1457}
14151458
...@@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" {...@@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" {
1465 const VecB = @Vector(4, u32);1508 const VecB = @Vector(4, u32);
14661509
1467 var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 };1510 var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 };
1468 var vec_b: VecB = @bitCast(vec_a);1511 _ = &vec_a;
1469 var vec_c: VecA = @bitCast(vec_b);1512 const vec_b: VecB = @bitCast(vec_a);
1513 const vec_c: VecA = @bitCast(vec_b);
1470 try expectEqual(vec_a, vec_c);1514 try expectEqual(vec_a, vec_c);
1471 }1515 }
1472 };1516 };
test/behavior/void.zig+3-1
...@@ -38,16 +38,18 @@ test "void optional" {...@@ -38,16 +38,18 @@ test "void optional" {
38 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO38 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3939
40 var x: ?void = {};40 var x: ?void = {};
41 _ = &x;
41 try expect(x != null);42 try expect(x != null);
42}43}
4344
44test "void array as a local variable initializer" {45test "void array as a local variable initializer" {
45 var x = [_]void{{}} ** 1004;46 var x = [_]void{{}} ** 1004;
47 _ = &x[0];
46 _ = x[0];48 _ = x[0];
47}49}
4850
49const void_constant = {};51const void_constant = {};
50test "reference to void constants" {52test "reference to void constants" {
51 var a = void_constant;53 var a = void_constant;
52 _ = a;54 _ = &a;
53}55}
test/behavior/wasm.zig+1
...@@ -4,6 +4,7 @@ const builtin = @import("builtin");...@@ -4,6 +4,7 @@ const builtin = @import("builtin");
44
5test "memory size and grow" {5test "memory size and grow" {
6 var prev = @wasmMemorySize(0);6 var prev = @wasmMemorySize(0);
7 _ = &prev;
7 try expect(prev == @wasmMemoryGrow(0, 1));8 try expect(prev == @wasmMemoryGrow(0, 1));
8 try expect(prev + 1 == @wasmMemorySize(0));9 try expect(prev + 1 == @wasmMemorySize(0));
9}10}
test/behavior/widening.zig+5
...@@ -15,6 +15,7 @@ test "integer widening" {...@@ -15,6 +15,7 @@ test "integer widening" {
15 var d: u64 = c;15 var d: u64 = c;
16 var e: u64 = d;16 var e: u64 = d;
17 var f: u128 = e;17 var f: u128 = e;
18 _ = .{ &a, &b, &c, &d, &e, &f };
18 try expect(f == a);19 try expect(f == a);
19}20}
2021
...@@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" {...@@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" {
3334
34 var a: u8 = 250;35 var a: u8 = 250;
35 var b: i16 = a;36 var b: i16 = a;
37 _ = .{ &a, &b };
36 try expect(b == 250);38 try expect(b == 250);
37}39}
3840
...@@ -47,10 +49,12 @@ test "float widening" {...@@ -47,10 +49,12 @@ test "float widening" {
47 var b: f32 = a;49 var b: f32 = a;
48 var c: f64 = b;50 var c: f64 = b;
49 var d: f128 = c;51 var d: f128 = c;
52 _ = .{ &a, &b, &c, &d };
50 try expect(a == b);53 try expect(a == b);
51 try expect(b == c);54 try expect(b == c);
52 try expect(c == d);55 try expect(c == d);
53 var e: f80 = c;56 var e: f80 = c;
57 _ = &e;
54 try expect(c == e);58 try expect(c == e);
55}59}
5660
...@@ -63,6 +67,7 @@ test "float widening f16 to f128" {...@@ -63,6 +67,7 @@ test "float widening f16 to f128" {
6367
64 var x: f16 = 12.34;68 var x: f16 = 12.34;
65 var y: f128 = x;69 var y: f128 = x;
70 _ = .{ &x, &y };
66 try expect(x == y);71 try expect(x == y);
67}72}
6873