| author | |
| committer | |
| log | 9c16b2370d30e74a63a84a835d840266021424fd |
| tree | 9447b9b05beb2e181d8fba96fd28b333d41792c4 |
| parent | 21fa187abc2a06c9bd5cfe4355c5edbfb3177f6b |
| signature |
104 files changed, 1160 insertions(+), 390 deletions(-)
test/behavior/abs.zig+33| ... | ... | @@ -16,26 +16,32 @@ test "@abs integers" { |
| 16 | 16 | fn testAbsIntegers() !void { |
| 17 | 17 | { |
| 18 | 18 | var x: i32 = -1000; |
| 19 | _ = &x; | |
| 19 | 20 | try expect(@abs(x) == 1000); |
| 20 | 21 | } |
| 21 | 22 | { |
| 22 | 23 | var x: i32 = 0; |
| 24 | _ = &x; | |
| 23 | 25 | try expect(@abs(x) == 0); |
| 24 | 26 | } |
| 25 | 27 | { |
| 26 | 28 | var x: i32 = 1000; |
| 29 | _ = &x; | |
| 27 | 30 | try expect(@abs(x) == 1000); |
| 28 | 31 | } |
| 29 | 32 | { |
| 30 | 33 | var x: i64 = std.math.minInt(i64); |
| 34 | _ = &x; | |
| 31 | 35 | try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); |
| 32 | 36 | } |
| 33 | 37 | { |
| 34 | 38 | var x: i5 = -1; |
| 39 | _ = &x; | |
| 35 | 40 | try expect(@abs(x) == 1); |
| 36 | 41 | } |
| 37 | 42 | { |
| 38 | 43 | var x: i5 = -5; |
| 44 | _ = &x; | |
| 39 | 45 | try expect(@abs(x) == 5); |
| 40 | 46 | } |
| 41 | 47 | comptime { |
| ... | ... | @@ -56,22 +62,27 @@ test "@abs unsigned integers" { |
| 56 | 62 | fn testAbsUnsignedIntegers() !void { |
| 57 | 63 | { |
| 58 | 64 | var x: u32 = 1000; |
| 65 | _ = &x; | |
| 59 | 66 | try expect(@abs(x) == 1000); |
| 60 | 67 | } |
| 61 | 68 | { |
| 62 | 69 | var x: u32 = 0; |
| 70 | _ = &x; | |
| 63 | 71 | try expect(@abs(x) == 0); |
| 64 | 72 | } |
| 65 | 73 | { |
| 66 | 74 | var x: u32 = 1000; |
| 75 | _ = &x; | |
| 67 | 76 | try expect(@abs(x) == 1000); |
| 68 | 77 | } |
| 69 | 78 | { |
| 70 | 79 | var x: u5 = 1; |
| 80 | _ = &x; | |
| 71 | 81 | try expect(@abs(x) == 1); |
| 72 | 82 | } |
| 73 | 83 | { |
| 74 | 84 | var x: u5 = 5; |
| 85 | _ = &x; | |
| 75 | 86 | try expect(@abs(x) == 5); |
| 76 | 87 | } |
| 77 | 88 | comptime { |
| ... | ... | @@ -102,27 +113,33 @@ test "@abs floats" { |
| 102 | 113 | fn testAbsFloats(comptime T: type) !void { |
| 103 | 114 | { |
| 104 | 115 | var x: T = -2.62; |
| 116 | _ = &x; | |
| 105 | 117 | try expect(@abs(x) == 2.62); |
| 106 | 118 | } |
| 107 | 119 | { |
| 108 | 120 | var x: T = 2.62; |
| 121 | _ = &x; | |
| 109 | 122 | try expect(@abs(x) == 2.62); |
| 110 | 123 | } |
| 111 | 124 | { |
| 112 | 125 | var x: T = 0.0; |
| 126 | _ = &x; | |
| 113 | 127 | try expect(@abs(x) == 0.0); |
| 114 | 128 | } |
| 115 | 129 | { |
| 116 | 130 | var x: T = -std.math.pi; |
| 131 | _ = &x; | |
| 117 | 132 | try expect(@abs(x) == std.math.pi); |
| 118 | 133 | } |
| 119 | 134 | |
| 120 | 135 | { |
| 121 | 136 | var x: T = -std.math.inf(T); |
| 137 | _ = &x; | |
| 122 | 138 | try expect(@abs(x) == std.math.inf(T)); |
| 123 | 139 | } |
| 124 | 140 | { |
| 125 | 141 | var x: T = std.math.inf(T); |
| 142 | _ = &x; | |
| 126 | 143 | try expect(@abs(x) == std.math.inf(T)); |
| 127 | 144 | } |
| 128 | 145 | comptime { |
| ... | ... | @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { |
| 164 | 181 | { |
| 165 | 182 | var x: I32 = @splat(-10); |
| 166 | 183 | var y: U32 = @splat(10); |
| 184 | _ = .{ &x, &y }; | |
| 167 | 185 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 168 | 186 | } |
| 169 | 187 | { |
| 170 | 188 | var x: I32 = @splat(10); |
| 171 | 189 | var y: U32 = @splat(10); |
| 190 | _ = .{ &x, &y }; | |
| 172 | 191 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 173 | 192 | } |
| 174 | 193 | { |
| 175 | 194 | var x: I32 = @splat(0); |
| 176 | 195 | var y: U32 = @splat(0); |
| 196 | _ = .{ &x, &y }; | |
| 177 | 197 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 178 | 198 | } |
| 179 | 199 | { |
| 180 | 200 | var x: I64 = @splat(-10); |
| 181 | 201 | var y: U64 = @splat(10); |
| 202 | _ = .{ &x, &y }; | |
| 182 | 203 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 183 | 204 | } |
| 184 | 205 | { |
| 185 | 206 | var x: I64 = @splat(std.math.minInt(i64)); |
| 186 | 207 | var y: U64 = @splat(-std.math.minInt(i64)); |
| 208 | _ = .{ &x, &y }; | |
| 187 | 209 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 188 | 210 | } |
| 189 | 211 | { |
| 190 | 212 | var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); |
| 191 | 213 | var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); |
| 214 | _ = .{ &x, &y }; | |
| 192 | 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 | 248 | { |
| 226 | 249 | var x: U32 = @splat(10); |
| 227 | 250 | var y: U32 = @splat(10); |
| 251 | _ = .{ &x, &y }; | |
| 228 | 252 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 229 | 253 | } |
| 230 | 254 | { |
| 231 | 255 | var x: U32 = @splat(10); |
| 232 | 256 | var y: U32 = @splat(10); |
| 257 | _ = .{ &x, &y }; | |
| 233 | 258 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 234 | 259 | } |
| 235 | 260 | { |
| 236 | 261 | var x: U32 = @splat(0); |
| 237 | 262 | var y: U32 = @splat(0); |
| 263 | _ = .{ &x, &y }; | |
| 238 | 264 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 239 | 265 | } |
| 240 | 266 | { |
| 241 | 267 | var x: U64 = @splat(10); |
| 242 | 268 | var y: U64 = @splat(10); |
| 269 | _ = .{ &x, &y }; | |
| 243 | 270 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 244 | 271 | } |
| 245 | 272 | { |
| 246 | 273 | var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); |
| 247 | 274 | var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); |
| 275 | _ = .{ &x, &y }; | |
| 248 | 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 | 374 | { |
| 347 | 375 | var x: V = @splat(-7.5); |
| 348 | 376 | var y: V = @splat(7.5); |
| 377 | _ = .{ &x, &y }; | |
| 349 | 378 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 350 | 379 | } |
| 351 | 380 | { |
| 352 | 381 | var x: V = @splat(7.5); |
| 353 | 382 | var y: V = @splat(7.5); |
| 383 | _ = .{ &x, &y }; | |
| 354 | 384 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 355 | 385 | } |
| 356 | 386 | { |
| 357 | 387 | var x: V = @splat(0.0); |
| 358 | 388 | var y: V = @splat(0.0); |
| 389 | _ = .{ &x, &y }; | |
| 359 | 390 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 360 | 391 | } |
| 361 | 392 | { |
| 362 | 393 | var x: V = @splat(-std.math.pi); |
| 363 | 394 | var y: V = @splat(std.math.pi); |
| 395 | _ = .{ &x, &y }; | |
| 364 | 396 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 365 | 397 | } |
| 366 | 398 | { |
| 367 | 399 | var x: V = @splat(std.math.pi); |
| 368 | 400 | var y: V = @splat(std.math.pi); |
| 401 | _ = .{ &x, &y }; | |
| 369 | 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 | 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 30 | 30 | |
| 31 | 31 | var runtime_index: usize = 1; |
| 32 | _ = &runtime_index; | |
| 32 | 33 | const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; |
| 33 | 34 | try expect(@TypeOf(slice) == []u8); |
| 34 | 35 | try expect(slice.len == 0); |
| ... | ... | @@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" { |
| 438 | 439 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 |
| 439 | 440 | var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; |
| 440 | 441 | var runtime_zero: usize = 0; |
| 442 | _ = &runtime_zero; | |
| 441 | 443 | comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); |
| 442 | 444 | comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); |
| 443 | 445 | try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); |
| ... | ... | @@ -464,6 +466,7 @@ test "alignment of function with c calling convention" { |
| 464 | 466 | const a = @alignOf(@TypeOf(nothing)); |
| 465 | 467 | |
| 466 | 468 | var runtime_nothing = &nothing; |
| 469 | _ = &runtime_nothing; | |
| 467 | 470 | const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); |
| 468 | 471 | const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); |
| 469 | 472 | casted2(); |
| ... | ... | @@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" { |
| 486 | 489 | .nevermind = 1, |
| 487 | 490 | .badguy = 12, |
| 488 | 491 | }; |
| 492 | _ = &default_aligned; | |
| 489 | 493 | try expect(12 == default_aligned.badguy); |
| 490 | 494 | } |
| 491 | 495 | |
| ... | ... | @@ -579,10 +583,10 @@ test "comptime alloc alignment" { |
| 579 | 583 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 580 | 584 | |
| 581 | 585 | comptime var bytes1 = [_]u8{0}; |
| 582 | _ = bytes1; | |
| 586 | _ = &bytes1; | |
| 583 | 587 | |
| 584 | 588 | comptime var bytes2 align(256) = [_]u8{0}; |
| 585 | var bytes2_addr = @intFromPtr(&bytes2); | |
| 589 | const bytes2_addr = @intFromPtr(&bytes2); | |
| 586 | 590 | try expect(bytes2_addr & 0xff == 0); |
| 587 | 591 | } |
| 588 | 592 | |
| ... | ... | @@ -591,6 +595,7 @@ test "@alignCast null" { |
| 591 | 595 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 592 | 596 | |
| 593 | 597 | var ptr: ?*anyopaque = null; |
| 598 | _ = &ptr; | |
| 594 | 599 | const aligned: ?*anyopaque = @alignCast(ptr); |
| 595 | 600 | try expect(aligned == null); |
| 596 | 601 | } |
| ... | ... | @@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" { |
| 637 | 642 | var s32: S align(32) = .{}; |
| 638 | 643 | |
| 639 | 644 | var zero: usize = 0; |
| 645 | _ = &zero; | |
| 640 | 646 | |
| 641 | 647 | try expect(@intFromPtr(&s) % @alignOf(usize) == 0); |
| 642 | 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 | 31 | var buf: [1024]u8 align(64) = undefined; |
| 32 | 32 | var start: usize = 1; |
| 33 | 33 | var end: usize = undefined; |
| 34 | _ = .{ &start, &end }; | |
| 34 | 35 | try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); |
| 35 | 36 | try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); |
| 36 | 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 | 138 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 139 | 139 | |
| 140 | 140 | var array = [2]u8{ 1, 2 }; |
| 141 | _ = &array; | |
| 141 | 142 | try expect(array[0] == 1); |
| 142 | 143 | try expect(array[1] == 2); |
| 143 | 144 | } |
| ... | ... | @@ -146,7 +147,7 @@ test "array len field" { |
| 146 | 147 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 147 | 148 | |
| 148 | 149 | var arr = [4]u8{ 0, 0, 0, 0 }; |
| 149 | var ptr = &arr; | |
| 150 | const ptr = &arr; | |
| 150 | 151 | try expect(arr.len == 4); |
| 151 | 152 | try comptime expect(arr.len == 4); |
| 152 | 153 | try expect(ptr.len == 4); |
| ... | ... | @@ -163,7 +164,8 @@ test "array with sentinels" { |
| 163 | 164 | { |
| 164 | 165 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; |
| 165 | 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 | 169 | try expect(reinterpreted[0] == 0xde); |
| 168 | 170 | } |
| 169 | 171 | var arr: [3:0x55]u8 = undefined; |
| ... | ... | @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { |
| 225 | 227 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 226 | 228 | |
| 227 | 229 | var arr: [plusOne(10)]bool = undefined; |
| 230 | _ = &arr; | |
| 228 | 231 | try expect(arr.len == 11); |
| 229 | 232 | } |
| 230 | 233 | |
| ... | ... | @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { |
| 281 | 284 | const S = struct { |
| 282 | 285 | fn doTheTest() !void { |
| 283 | 286 | var array: [4]u8 = .{ 1, 2, 3, 4 }; |
| 287 | _ = &array; | |
| 284 | 288 | try expect(array[0] == 1); |
| 285 | 289 | try expect(array[1] == 2); |
| 286 | 290 | try expect(array[2] == 3); |
| ... | ... | @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { |
| 365 | 369 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 366 | 370 | |
| 367 | 371 | var two: i32 = 2; |
| 372 | _ = &two; | |
| 368 | 373 | const x: []const i32 = &[_]i32{two}; |
| 369 | 374 | try expect(x[0] == 2); |
| 370 | 375 | } |
| ... | ... | @@ -472,6 +477,7 @@ test "anonymous literal in array" { |
| 472 | 477 | .{ .a = 3 }, |
| 473 | 478 | .{ .b = 3 }, |
| 474 | 479 | }; |
| 480 | _ = &array; | |
| 475 | 481 | try expect(array[0].a == 3); |
| 476 | 482 | try expect(array[0].b == 4); |
| 477 | 483 | try expect(array[1].a == 2); |
| ... | ... | @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { |
| 489 | 495 | const S = struct { |
| 490 | 496 | fn doTheTest() !void { |
| 491 | 497 | var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; |
| 498 | _ = &array; | |
| 492 | 499 | try expect(array[4] == 0); |
| 493 | 500 | var len: usize = 4; |
| 501 | _ = &len; | |
| 494 | 502 | try expect(array[len] == 0); |
| 495 | 503 | } |
| 496 | 504 | }; |
| ... | ... | @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { |
| 510 | 518 | try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); |
| 511 | 519 | var v1 = false; |
| 512 | 520 | try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); |
| 521 | _ = .{ &array, &v0, &v1 }; | |
| 513 | 522 | } |
| 514 | 523 | }; |
| 515 | 524 | try S.doTheTest(); |
| ... | ... | @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { |
| 529 | 538 | fill_post: u8 = 0xAA, |
| 530 | 539 | }; |
| 531 | 540 | var x = T{}; |
| 532 | var as_slice = mem.asBytes(&x); | |
| 541 | const as_slice = mem.asBytes(&x); | |
| 533 | 542 | try expect(@as(usize, 3) == as_slice.len); |
| 534 | 543 | try expect(@as(u8, 0x55) == as_slice[0]); |
| 535 | 544 | try expect(@as(u8, 0xAA) == as_slice[2]); |
| ... | ... | @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { |
| 559 | 568 | }; |
| 560 | 569 | |
| 561 | 570 | var t: S = .{ .list = .{ .s = undefined } }; |
| 571 | _ = &t; | |
| 562 | 572 | try expect(@as(usize, 0) == t.list.x); |
| 563 | 573 | } |
| 564 | 574 | |
| ... | ... | @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { |
| 576 | 586 | |
| 577 | 587 | fn doTheTest() !void { |
| 578 | 588 | var x1: u8 = 42; |
| 589 | _ = &x1; | |
| 579 | 590 | const t1 = .{ x1, 56, 54 }; |
| 580 | var arr1: [3]u8 = t1; | |
| 591 | const arr1: [3]u8 = t1; | |
| 581 | 592 | try expect(arr1[0] == 42); |
| 582 | 593 | try expect(arr1[1] == 56); |
| 583 | 594 | try expect(arr1[2] == 54); |
| 584 | 595 | |
| 585 | 596 | var x2: U = .{ .a = 42 }; |
| 597 | _ = &x2; | |
| 586 | 598 | const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 587 | var arr2: [3]U = t2; | |
| 599 | const arr2: [3]U = t2; | |
| 588 | 600 | try expect(arr2[0].a == 42); |
| 589 | 601 | try expect(arr2[1].b == true); |
| 590 | 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 | 620 | |
| 609 | 621 | fn doTheTest() !void { |
| 610 | 622 | var x1: u8 = 42; |
| 623 | _ = &x1; | |
| 611 | 624 | const t1 = &.{ x1, 56, 54 }; |
| 612 | var arr1: *const [3]u8 = t1; | |
| 625 | const arr1: *const [3]u8 = t1; | |
| 613 | 626 | try expect(arr1[0] == 42); |
| 614 | 627 | try expect(arr1[1] == 56); |
| 615 | 628 | try expect(arr1[2] == 54); |
| 616 | 629 | |
| 617 | 630 | var x2: U = .{ .a = 42 }; |
| 631 | _ = &x2; | |
| 618 | 632 | const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 619 | var arr2: *const [3]U = t2; | |
| 633 | const arr2: *const [3]U = t2; | |
| 620 | 634 | try expect(arr2[0].a == 42); |
| 621 | 635 | try expect(arr2[1].b == true); |
| 622 | 636 | try expect(mem.eql(u8, arr2[2].c, "hello")); |
| ... | ... | @@ -656,6 +670,7 @@ test "array init of container level array variable" { |
| 656 | 670 | } |
| 657 | 671 | noinline fn bar(x: usize, y: usize) void { |
| 658 | 672 | var tmp: [2]usize = .{ x, y }; |
| 673 | _ = &tmp; | |
| 659 | 674 | pair = tmp; |
| 660 | 675 | } |
| 661 | 676 | }; |
| ... | ... | @@ -668,6 +683,7 @@ test "array init of container level array variable" { |
| 668 | 683 | |
| 669 | 684 | test "runtime initialized sentinel-terminated array literal" { |
| 670 | 685 | var c: u16 = 300; |
| 686 | _ = &c; | |
| 671 | 687 | const f = &[_:0x9999]u16{c}; |
| 672 | 688 | const g = @as(*const [4]u8, @ptrCast(f)); |
| 673 | 689 | try std.testing.expect(g[2] == 0x99); |
| ... | ... | @@ -681,6 +697,7 @@ test "array of array agregate init" { |
| 681 | 697 | |
| 682 | 698 | var a = [1]u32{11} ** 10; |
| 683 | 699 | var b = [1][10]u32{a} ** 2; |
| 700 | _ = .{ &a, &b }; | |
| 684 | 701 | try std.testing.expect(b[1][1] == 11); |
| 685 | 702 | } |
| 686 | 703 | |
| ... | ... | @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { |
| 778 | 795 | test "slice initialized through reference to anonymous array init provides result types" { |
| 779 | 796 | var my_u32: u32 = 123; |
| 780 | 797 | var my_u64: u64 = 456; |
| 798 | _ = .{ &my_u32, &my_u64 }; | |
| 781 | 799 | const foo: []const u16 = &.{ |
| 782 | 800 | @intCast(my_u32), |
| 783 | 801 | @intCast(my_u64), |
| ... | ... | @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul |
| 790 | 808 | test "pointer to array initialized through reference to anonymous array init provides result types" { |
| 791 | 809 | var my_u32: u32 = 123; |
| 792 | 810 | var my_u64: u64 = 456; |
| 811 | _ = .{ &my_u32, &my_u64 }; | |
| 793 | 812 | const foo: *const [4]u16 = &.{ |
| 794 | 813 | @intCast(my_u32), |
| 795 | 814 | @intCast(my_u64), |
test/behavior/asm.zig+1| ... | ... | @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { |
| 180 | 180 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly |
| 181 | 181 | |
| 182 | 182 | var x: u32 = 15; |
| 183 | _ = &x; | |
| 183 | 184 | const double = asm ("add %[ret:w], %[in:w], %[in:w]" |
| 184 | 185 | : [ret] "=r" (-> u32), |
| 185 | 186 | : [in] "r" (x), |
test/behavior/async_fn.zig+22-10| ... | ... | @@ -137,11 +137,13 @@ test "@frameSize" { |
| 137 | 137 | fn doTheTest() !void { |
| 138 | 138 | { |
| 139 | 139 | var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); |
| 140 | _ = &ptr; | |
| 140 | 141 | const size = @frameSize(ptr); |
| 141 | 142 | try expect(size == @sizeOf(@Frame(other))); |
| 142 | 143 | } |
| 143 | 144 | { |
| 144 | 145 | var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); |
| 146 | _ = &ptr; | |
| 145 | 147 | const size = @frameSize(ptr); |
| 146 | 148 | try expect(size == @sizeOf(@Frame(first))); |
| 147 | 149 | } |
| ... | ... | @@ -153,7 +155,7 @@ test "@frameSize" { |
| 153 | 155 | fn other(param: i32) void { |
| 154 | 156 | _ = param; |
| 155 | 157 | var local: i32 = undefined; |
| 156 | _ = local; | |
| 158 | _ = &local; | |
| 157 | 159 | suspend {} |
| 158 | 160 | } |
| 159 | 161 | }; |
| ... | ... | @@ -239,7 +241,7 @@ test "coroutine await" { |
| 239 | 241 | |
| 240 | 242 | await_seq('a'); |
| 241 | 243 | var p = async await_amain(); |
| 242 | _ = p; | |
| 244 | _ = &p; | |
| 243 | 245 | await_seq('f'); |
| 244 | 246 | resume await_a_promise; |
| 245 | 247 | await_seq('i'); |
| ... | ... | @@ -279,7 +281,7 @@ test "coroutine await early return" { |
| 279 | 281 | |
| 280 | 282 | early_seq('a'); |
| 281 | 283 | var p = async early_amain(); |
| 282 | _ = p; | |
| 284 | _ = &p; | |
| 283 | 285 | early_seq('f'); |
| 284 | 286 | try expect(early_final_result == 1234); |
| 285 | 287 | try expect(std.mem.eql(u8, &early_points, "abcdef")); |
| ... | ... | @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { |
| 329 | 331 | bar: fn (*i32) callconv(.Async) void, |
| 330 | 332 | }; |
| 331 | 333 | var foo = Foo{ .bar = simpleAsyncFn2 }; |
| 334 | _ = &foo; | |
| 332 | 335 | var bytes: [64]u8 align(16) = undefined; |
| 333 | 336 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 334 | 337 | try comptime expect(@TypeOf(f) == anyframe->void); |
| ... | ... | @@ -367,6 +370,7 @@ test "@asyncCall with return type" { |
| 367 | 370 | } |
| 368 | 371 | }; |
| 369 | 372 | var foo = Foo{ .bar = Foo.middle }; |
| 373 | _ = &foo; | |
| 370 | 374 | var bytes: [150]u8 align(16) = undefined; |
| 371 | 375 | var aresult: i32 = 0; |
| 372 | 376 | _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); |
| ... | ... | @@ -385,6 +389,7 @@ test "async fn with inferred error set" { |
| 385 | 389 | fn doTheTest() !void { |
| 386 | 390 | var frame: [1]@Frame(middle) = undefined; |
| 387 | 391 | var fn_ptr = middle; |
| 392 | _ = &fn_ptr; | |
| 388 | 393 | var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; |
| 389 | 394 | _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); |
| 390 | 395 | resume global_frame; |
| ... | ... | @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { |
| 827 | 832 | const S = struct { |
| 828 | 833 | fn doTheTest() !void { |
| 829 | 834 | var y: u8 = 123; |
| 830 | _ = y; | |
| 835 | _ = &y; | |
| 831 | 836 | var x: u8 align(128) = 1; |
| 832 | 837 | try expect(@intFromPtr(&x) % 128 == 0); |
| 833 | 838 | } |
| ... | ... | @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { |
| 843 | 848 | } |
| 844 | 849 | fn simpleNothing() void { |
| 845 | 850 | var x: i32 = 1234; |
| 846 | _ = x; | |
| 851 | _ = &x; | |
| 847 | 852 | } |
| 848 | 853 | |
| 849 | 854 | test "async call a generic function" { |
| ... | ... | @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { |
| 913 | 918 | if (x == 0) return; |
| 914 | 919 | clobberStack(x - 1); |
| 915 | 920 | var y: i32 = x; |
| 916 | _ = y; | |
| 921 | _ = &y; | |
| 917 | 922 | } |
| 918 | 923 | |
| 919 | 924 | fn bar(f: *@Frame(foo)) void { |
| 920 | 925 | var pt = Point{ .x = 1, .y = 2 }; |
| 926 | _ = &pt; | |
| 921 | 927 | f.* = async foo(pt); |
| 922 | var result = await f; | |
| 928 | const result = await f; | |
| 923 | 929 | expect(result == 1) catch @panic("test failure"); |
| 924 | 930 | } |
| 925 | 931 | |
| ... | ... | @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { |
| 1141 | 1147 | bar: fn (*i32) callconv(.Async) i32, |
| 1142 | 1148 | }; |
| 1143 | 1149 | var foo = Foo{ .bar = S.simple2 }; |
| 1150 | _ = &foo; | |
| 1144 | 1151 | var bytes: [64]u8 align(16) = undefined; |
| 1145 | 1152 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 1146 | 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 | 1472 | // the for loop spills still happen even though there is a VarDecl in scope |
| 1466 | 1473 | // before the suspend. |
| 1467 | 1474 | var anything = true; |
| 1468 | _ = anything; | |
| 1475 | _ = &anything; | |
| 1469 | 1476 | suspend { |
| 1470 | 1477 | global_frame = @frame(); |
| 1471 | 1478 | } |
| ... | ... | @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { |
| 1538 | 1545 | |
| 1539 | 1546 | fn foo() void { |
| 1540 | 1547 | var a: u128 = 99; |
| 1548 | _ = &a; | |
| 1541 | 1549 | bar(10, .{a}) catch unreachable; |
| 1542 | 1550 | } |
| 1543 | 1551 | |
| ... | ... | @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { |
| 1590 | 1598 | const stack_size = 1000; |
| 1591 | 1599 | var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; |
| 1592 | 1600 | var func: fn () callconv(.Async) anyerror!void = bar; |
| 1601 | _ = &func; | |
| 1593 | 1602 | return await @asyncCall(&stack_frame, {}, func, .{}); |
| 1594 | 1603 | } |
| 1595 | 1604 | |
| ... | ... | @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { |
| 1614 | 1623 | |
| 1615 | 1624 | fn foo() void { |
| 1616 | 1625 | var opt: ?usize = 1234; |
| 1626 | _ = &opt; | |
| 1617 | 1627 | if (opt) |x| { |
| 1618 | 1628 | bar(); |
| 1619 | 1629 | global_int += x; |
| ... | ... | @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { |
| 1863 | 1873 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; |
| 1864 | 1874 | // The function pointer must not be comptime-known. |
| 1865 | 1875 | var t = S.f; |
| 1876 | _ = &t; | |
| 1866 | 1877 | var frame_ptr = @asyncCall(&buffer, {}, t, .{ |
| 1867 | 1878 | F0, |
| 1868 | 1879 | .{ .f0 = 1, .f1 = 2 }, |
| ... | ... | @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { |
| 1870 | 1881 | [_]u8{ 1, 2, 3, 4, 5 }, |
| 1871 | 1882 | F2, |
| 1872 | 1883 | }); |
| 1873 | _ = frame_ptr; | |
| 1884 | _ = &frame_ptr; | |
| 1874 | 1885 | } |
| 1875 | 1886 | |
| 1876 | 1887 | test "@asyncCall with arguments having non-standard alignment" { |
| ... | ... | @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { |
| 1893 | 1904 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; |
| 1894 | 1905 | // The function pointer must not be comptime-known. |
| 1895 | 1906 | var t = S.f; |
| 1907 | _ = &t; | |
| 1896 | 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 | 14 | |
| 15 | 15 | await_seq('a'); |
| 16 | 16 | var p = async await_amain(); |
| 17 | _ = p; | |
| 17 | _ = &p; | |
| 18 | 18 | await_seq('f'); |
| 19 | 19 | resume await_a_promise; |
| 20 | 20 | await_seq('i'); |
test/behavior/basic.zig+16-3| ... | ... | @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { |
| 118 | 118 | |
| 119 | 119 | test "unicode escape in character literal" { |
| 120 | 120 | var a: u24 = '\u{01f4a9}'; |
| 121 | _ = &a; | |
| 121 | 122 | try expect(a == 128169); |
| 122 | 123 | } |
| 123 | 124 | |
| ... | ... | @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { |
| 362 | 363 | } |
| 363 | 364 | fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { |
| 364 | 365 | var a = ptr; |
| 366 | _ = &a; | |
| 365 | 367 | return a; |
| 366 | 368 | } |
| 367 | 369 | |
| ... | ... | @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { |
| 441 | 443 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 442 | 444 | |
| 443 | 445 | var x = @as(i32, @as(u16, nine())); |
| 446 | _ = &x; | |
| 444 | 447 | try expect(x == 9); |
| 445 | 448 | } |
| 446 | 449 | fn nine() u8 { |
| ... | ... | @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { |
| 570 | 573 | |
| 571 | 574 | test "equality compare fn ptrs" { |
| 572 | 575 | var a = &emptyFn; |
| 576 | _ = &a; | |
| 573 | 577 | try expect(a == a); |
| 574 | 578 | } |
| 575 | 579 | |
| ... | ... | @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { |
| 611 | 615 | const S = struct { |
| 612 | 616 | fn doTheTest() !void { |
| 613 | 617 | var index: usize = 1; |
| 618 | _ = &index; | |
| 614 | 619 | const ptr = &pieces[index].field; |
| 615 | 620 | try expect(ptr.* == 2); |
| 616 | 621 | } |
| ... | ... | @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { |
| 785 | 790 | |
| 786 | 791 | test "if expression type coercion" { |
| 787 | 792 | var cond: bool = true; |
| 793 | _ = &cond; | |
| 788 | 794 | const x: u16 = if (cond) 1 else 0; |
| 789 | 795 | try expect(@as(u16, x) == 1); |
| 790 | 796 | } |
| ... | ... | @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { |
| 825 | 831 | |
| 826 | 832 | test "labeled block implicitly ends in a break" { |
| 827 | 833 | var a = false; |
| 834 | _ = &a; | |
| 828 | 835 | blk: { |
| 829 | 836 | if (a) break :blk; |
| 830 | 837 | } |
| ... | ... | @@ -852,6 +859,7 @@ test "catch in block has correct result location" { |
| 852 | 859 | test "labeled block with runtime branch forwards its result location type to break statements" { |
| 853 | 860 | const E = enum { a, b }; |
| 854 | 861 | var a = false; |
| 862 | _ = &a; | |
| 855 | 863 | const e: E = blk: { |
| 856 | 864 | if (a) { |
| 857 | 865 | break :blk .a; |
| ... | ... | @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { |
| 872 | 880 | }; |
| 873 | 881 | const s: ?*S = blk: { |
| 874 | 882 | var a = try S.foo(); |
| 875 | ||
| 876 | _ = a; | |
| 883 | _ = &a; | |
| 877 | 884 | break :blk null; |
| 878 | 885 | }; |
| 879 | 886 | _ = s; |
| ... | ... | @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { |
| 894 | 901 | const E = enum { a, b }; |
| 895 | 902 | const S = struct { e: E }; |
| 896 | 903 | var a = false; |
| 904 | _ = &a; | |
| 897 | 905 | const b = S{ .e = .a }; |
| 898 | 906 | |
| 899 | 907 | _ = &[_]S{ |
| ... | ... | @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { |
| 1009 | 1017 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1010 | 1018 | |
| 1011 | 1019 | var a: u32 = 0; |
| 1020 | _ = &a; | |
| 1012 | 1021 | var b: [2]u32 = undefined; |
| 1013 | 1022 | b[0] = @as(u32, switch (a) { |
| 1014 | 1023 | 1 => 1, |
| ... | ... | @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { |
| 1110 | 1119 | } |
| 1111 | 1120 | }; |
| 1112 | 1121 | var optional: ?Loc = .{}; |
| 1113 | var foo = Container.init(optional orelse .{}); | |
| 1122 | _ = &optional; | |
| 1123 | const foo = Container.init(optional orelse .{}); | |
| 1114 | 1124 | try expect(foo.a.?.start == -1); |
| 1115 | 1125 | } |
| 1116 | 1126 | |
| ... | ... | @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { |
| 1153 | 1163 | test "pointer to struct literal with runtime field is constant" { |
| 1154 | 1164 | const S = struct { data: usize }; |
| 1155 | 1165 | var runtime_zero: usize = 0; |
| 1166 | _ = &runtime_zero; | |
| 1156 | 1167 | const ptr = &S{ .data = runtime_zero }; |
| 1157 | 1168 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); |
| 1158 | 1169 | } |
| ... | ... | @@ -1163,6 +1174,7 @@ test "integer compare" { |
| 1163 | 1174 | var z: T = 0; |
| 1164 | 1175 | var p: T = 123; |
| 1165 | 1176 | var n: T = -123; |
| 1177 | _ = .{ &z, &p, &n }; | |
| 1166 | 1178 | try expect(z == z and z != p and z != n); |
| 1167 | 1179 | try expect(p == p and p != n and n == n); |
| 1168 | 1180 | try expect(z > n and z < p and z >= n and z <= p); |
| ... | ... | @@ -1180,6 +1192,7 @@ test "integer compare" { |
| 1180 | 1192 | fn doTheTestUnsigned(comptime T: type) !void { |
| 1181 | 1193 | var z: T = 0; |
| 1182 | 1194 | var p: T = 123; |
| 1195 | _ = .{ &z, &p }; | |
| 1183 | 1196 | try expect(z == z and z != p); |
| 1184 | 1197 | try expect(p == p); |
| 1185 | 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 | 99 | // #2225 |
| 100 | 100 | test "comptime shr of BigInt" { |
| 101 | 101 | comptime { |
| 102 | var n0 = 0xdeadbeef0000000000000000; | |
| 102 | const n0 = 0xdeadbeef0000000000000000; | |
| 103 | 103 | try expect(n0 >> 64 == 0xdeadbeef); |
| 104 | var n1 = 17908056155735594659; | |
| 104 | const n1 = 17908056155735594659; | |
| 105 | 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 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "bitcast generates a temporary value" { |
| 152 | var y = @as(u16, 0x55AA); | |
| 153 | const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); | |
| 152 | var y: u16 = 0x55AA; | |
| 153 | _ = &y; | |
| 154 | const x: u16 = @bitCast(@as([2]u8, @bitCast(y))); | |
| 154 | 155 | try expect(y == x); |
| 155 | 156 | } |
| 156 | 157 | |
| ... | ... | @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { |
| 171 | 172 | const S = struct { |
| 172 | 173 | fn doTheTest() !void { |
| 173 | 174 | var full = Full{ .number = 0x1234 }; |
| 174 | var two_halves = @as(Divided, @bitCast(full)); | |
| 175 | _ = &full; | |
| 176 | const two_halves: Divided = @bitCast(full); | |
| 175 | 177 | try expect(two_halves.half1 == 0x34); |
| 176 | 178 | try expect(two_halves.quarter3 == 0x2); |
| 177 | 179 | try expect(two_halves.quarter4 == 0x1); |
| ... | ... | @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { |
| 195 | 197 | const S = struct { |
| 196 | 198 | fn doTheTest() !void { |
| 197 | 199 | var full = Full{ .number = 0x1234 }; |
| 198 | var two_halves = @as(TwoHalves, @bitCast(full)); | |
| 200 | _ = &full; | |
| 201 | const two_halves: TwoHalves = @bitCast(full); | |
| 199 | 202 | switch (native_endian) { |
| 200 | 203 | .big => { |
| 201 | 204 | try expect(two_halves.half1 == 0x12); |
| ... | ... | @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { |
| 225 | 228 | const S = struct { |
| 226 | 229 | fn doTheTest() !void { |
| 227 | 230 | var move = LevelUpMove{ .move_id = 1, .level = 2 }; |
| 228 | var v = @as(u16, @bitCast(move)); | |
| 229 | var back_to_a_move = @as(LevelUpMove, @bitCast(v)); | |
| 231 | _ = &move; | |
| 232 | const v: u16 = @bitCast(move); | |
| 233 | const back_to_a_move: LevelUpMove = @bitCast(v); | |
| 230 | 234 | try expect(back_to_a_move.move_id == 1); |
| 231 | 235 | try expect(back_to_a_move.level == 2); |
| 232 | 236 | } |
| ... | ... | @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { |
| 312 | 316 | const S = struct { |
| 313 | 317 | fn doTheTest() !void { |
| 314 | 318 | var foo = Foo{}; |
| 315 | var v = @as(Foo2, @bitCast(foo)); | |
| 319 | _ = &foo; | |
| 320 | const v: Foo2 = @bitCast(foo); | |
| 316 | 321 | try expect(v.a == foo.a); |
| 317 | 322 | try expect(v.b == foo.b); |
| 318 | 323 | try expect(v.c == foo.c); |
| ... | ... | @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { |
| 354 | 359 | |
| 355 | 360 | // S -> Int |
| 356 | 361 | var s: S = .{}; |
| 362 | _ = &s; | |
| 357 | 363 | try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); |
| 358 | 364 | |
| 359 | 365 | // Int -> S |
| 360 | 366 | var i: Int = 0; |
| 367 | _ = &i; | |
| 361 | 368 | const rt_cast = @as(S, @bitCast(i)); |
| 362 | 369 | const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); |
| 363 | 370 | inline for (@typeInfo(S).Struct.fields) |field| { |
| ... | ... | @@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" { |
| 376 | 383 | const FloatT = extern struct { f: f80, x: u128 align(16) }; |
| 377 | 384 | const x: FloatT = .{ .f = 0.5, .x = 123 }; |
| 378 | 385 | var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); |
| 386 | _ = &x_as_uint; | |
| 379 | 387 | |
| 380 | 388 | try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); |
| 381 | 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 | 436 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); |
| 429 | 437 | |
| 430 | 438 | var snan_f16_var = math.snan(f16); |
| 439 | _ = &snan_f16_var; | |
| 431 | 440 | try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); |
| 432 | 441 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); |
| 433 | 442 | |
| ... | ... | @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 437 | 446 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); |
| 438 | 447 | |
| 439 | 448 | var snan_f32_var = math.snan(f32); |
| 449 | _ = &snan_f32_var; | |
| 440 | 450 | try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); |
| 441 | 451 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); |
| 442 | 452 | |
| ... | ... | @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 446 | 456 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); |
| 447 | 457 | |
| 448 | 458 | var snan_f64_var = math.snan(f64); |
| 459 | _ = &snan_f64_var; | |
| 449 | 460 | try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); |
| 450 | 461 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); |
| 451 | 462 | |
| ... | ... | @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 455 | 466 | try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); |
| 456 | 467 | |
| 457 | 468 | var snan_f128_var = math.snan(f128); |
| 469 | _ = &snan_f128_var; | |
| 458 | 470 | try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); |
| 459 | 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 | 86 | try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); |
| 87 | 87 | var neg32: i32 = -16773785; |
| 88 | 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 | } |
| 90 | 108 | |
| 91 | 109 | fn vector8() !void { |
| 92 | 110 | var v = @Vector(2, u8){ 0x12, 0x23 }; |
| 93 | var result = @bitReverse(v); | |
| 111 | _ = &v; | |
| 112 | const result = @bitReverse(v); | |
| 94 | 113 | try expect(result[0] == 0x48); |
| 95 | 114 | try expect(result[1] == 0xc4); |
| 96 | 115 | } |
| ... | ... | @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { |
| 109 | 128 | |
| 110 | 129 | fn vector16() !void { |
| 111 | 130 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 112 | var result = @bitReverse(v); | |
| 131 | _ = &v; | |
| 132 | const result = @bitReverse(v); | |
| 113 | 133 | try expect(result[0] == 0x2c48); |
| 114 | 134 | try expect(result[1] == 0xa2c4); |
| 115 | 135 | } |
| ... | ... | @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { |
| 128 | 148 | |
| 129 | 149 | fn vector24() !void { |
| 130 | 150 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 131 | var result = @bitReverse(v); | |
| 151 | _ = &v; | |
| 152 | const result = @bitReverse(v); | |
| 132 | 153 | try expect(result[0] == 0x6a2c48); |
| 133 | 154 | try expect(result[1] == 0xe6a2c4); |
| 134 | 155 | } |
| ... | ... | @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { |
| 147 | 168 | |
| 148 | 169 | fn vector0() !void { |
| 149 | 170 | var v = @Vector(2, u0){ 0, 0 }; |
| 150 | var result = @bitReverse(v); | |
| 171 | _ = &v; | |
| 172 | const result = @bitReverse(v); | |
| 151 | 173 | try expect(result[0] == 0); |
| 152 | 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 | 10 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 11 | 11 | |
| 12 | 12 | var x: u32 = 0x1; |
| 13 | _ = &x; | |
| 13 | 14 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; |
| 14 | var a = @clz(x); | |
| 15 | var b = @clz(y); | |
| 15 | _ = &y; | |
| 16 | const a = @clz(x); | |
| 17 | const b = @clz(y); | |
| 16 | 18 | try std.testing.expectEqual(@as(u6, 31), a); |
| 17 | 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 | 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 10 | 10 | |
| 11 | 11 | var cond = true; |
| 12 | _ = &cond; | |
| 12 | 13 | const opt = while (cond) { |
| 13 | 14 | if (retOpt()) |opt| { |
| 14 | 15 | break opt; |
test/behavior/bugs/11046.zig+1| ... | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | |
| 3 | 3 | fn foo() !void { |
| 4 | 4 | var a = true; |
| 5 | _ = &a; | |
| 5 | 6 | if (a) return error.Foo; |
| 6 | 7 | return error.Bar; |
| 7 | 8 | } |
test/behavior/bugs/11139.zig+1| ... | ... | @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { |
| 21 | 21 | S{ .x = 15 }, |
| 22 | 22 | }, |
| 23 | 23 | }; |
| 24 | _ = &cases; | |
| 24 | 25 | return cases[0][0].x; |
| 25 | 26 | } |
test/behavior/bugs/11159.zig+3-3| ... | ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); |
| 4 | 4 | test { |
| 5 | 5 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); |
| 6 | 6 | var a: T = .{ 0, 0 }; |
| 7 | _ = a; | |
| 7 | _ = &a; | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | test { |
| ... | ... | @@ -13,7 +13,7 @@ test { |
| 13 | 13 | comptime y: u32 = 0, |
| 14 | 14 | }; |
| 15 | 15 | var a: S = .{}; |
| 16 | _ = a; | |
| 16 | _ = &a; | |
| 17 | 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 | 6 | if (true) return error.SkipZigTest; // TODO |
| 7 | 7 | |
| 8 | 8 | var x: u32 = 15; |
| 9 | _ = &x; | |
| 9 | 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 }; | |
| 11 | 12 | |
| 12 | 13 | try expect(a[0] == -1234); |
| 13 | 14 | try expect(a[1] == 5678); |
test/behavior/bugs/11165.zig+2-2| ... | ... | @@ -18,7 +18,7 @@ test "bytes" { |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | var u_2 = U{ .s = s_1 }; |
| 21 | _ = u_2; | |
| 21 | _ = &u_2; | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | test "aggregate" { |
| ... | ... | @@ -40,5 +40,5 @@ test "aggregate" { |
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | 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 | 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 | 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 12 | 12 | |
| 13 | 13 | var t: T = .{ .next = null }; |
| 14 | _ = &t; | |
| 14 | 15 | try std.testing.expect(t.next == null); |
| 15 | 16 | } |
test/behavior/bugs/12025.zig+1| ... | ... | @@ -5,6 +5,7 @@ test { |
| 5 | 5 | .foo = &1, |
| 6 | 6 | .bar = &2, |
| 7 | 7 | }; |
| 8 | _ = &st; | |
| 8 | 9 | |
| 9 | 10 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { |
| 10 | 11 | _ = field; |
test/behavior/bugs/12092.zig+1| ... | ... | @@ -19,6 +19,7 @@ test { |
| 19 | 19 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 20 | 20 | |
| 21 | 21 | var baz: u32 = 24; |
| 22 | _ = &baz; | |
| 22 | 23 | try takeFoo(&.{ |
| 23 | 24 | .a = .{ |
| 24 | 25 | .b = baz, |
test/behavior/bugs/12498.zig+1| ... | ... | @@ -4,5 +4,6 @@ const expect = std.testing.expect; |
| 4 | 4 | const S = struct { a: usize }; |
| 5 | 5 | test "lazy abi size used in comparison" { |
| 6 | 6 | var rhs: i32 = 100; |
| 7 | _ = &rhs; | |
| 7 | 8 | try expect(@sizeOf(S) < rhs); |
| 8 | 9 | } |
test/behavior/bugs/12776.zig+1| ... | ... | @@ -22,6 +22,7 @@ const CPU = packed struct { |
| 22 | 22 | } |
| 23 | 23 | fn tick(self: *CPU) !void { |
| 24 | 24 | var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); |
| 25 | _ = &queued_interrupts; | |
| 25 | 26 | if (self.interrupts and queued_interrupts != 0) { |
| 26 | 27 | self.interrupts = false; |
| 27 | 28 | } |
test/behavior/bugs/12891.zig+5| ... | ... | @@ -4,26 +4,31 @@ const builtin = @import("builtin"); |
| 4 | 4 | test "issue12891" { |
| 5 | 5 | const f = 10.0; |
| 6 | 6 | var i: usize = 0; |
| 7 | _ = &i; | |
| 7 | 8 | try std.testing.expect(i < f); |
| 8 | 9 | } |
| 9 | 10 | test "nan" { |
| 10 | 11 | const f = comptime std.math.nan(f64); |
| 11 | 12 | var i: usize = 0; |
| 13 | _ = &i; | |
| 12 | 14 | try std.testing.expect(!(f < i)); |
| 13 | 15 | } |
| 14 | 16 | test "inf" { |
| 15 | 17 | const f = comptime std.math.inf(f64); |
| 16 | 18 | var i: usize = 0; |
| 19 | _ = &i; | |
| 17 | 20 | try std.testing.expect(f > i); |
| 18 | 21 | } |
| 19 | 22 | test "-inf < 0" { |
| 20 | 23 | const f = comptime -std.math.inf(f64); |
| 21 | 24 | var i: usize = 0; |
| 25 | _ = &i; | |
| 22 | 26 | try std.testing.expect(f < i); |
| 23 | 27 | } |
| 24 | 28 | test "inf >= 1" { |
| 25 | 29 | const f = comptime std.math.inf(f64); |
| 26 | 30 | var i: usize = 1; |
| 31 | _ = &i; | |
| 27 | 32 | try std.testing.expect(f >= i); |
| 28 | 33 | } |
| 29 | 34 | test "isNan(nan * 1)" { |
test/behavior/bugs/12972.zig+1| ... | ... | @@ -12,6 +12,7 @@ test { |
| 12 | 12 | f(&.{c}); |
| 13 | 13 | |
| 14 | 14 | var v: u8 = 42; |
| 15 | _ = &v; | |
| 15 | 16 | f(&[_:null]?u8{v}); |
| 16 | 17 | f(&.{v}); |
| 17 | 18 | } |
test/behavior/bugs/12984.zig+1-1| ... | ... | @@ -16,5 +16,5 @@ test "simple test" { |
| 16 | 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 17 | 17 | |
| 18 | 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 | 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 19 | 19 | |
| 20 | 20 | var x: u8 = 1; |
| 21 | _ = &x; | |
| 21 | 22 | try foo(.{ .x = x }); |
| 22 | 23 | |
| 23 | 24 | const val: U = @unionInit(U, "x", x); |
test/behavior/bugs/13159.zig+1| ... | ... | @@ -13,5 +13,6 @@ test { |
| 13 | 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 14 | 14 | |
| 15 | 15 | var foo = Bar.Baz.fizz; |
| 16 | _ = &foo; | |
| 16 | 17 | try expect(foo == .fizz); |
| 17 | 18 | } |
test/behavior/bugs/13285.zig+1-1| ... | ... | @@ -8,7 +8,7 @@ test { |
| 8 | 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 9 | 9 | |
| 10 | 10 | var a: Crasher = undefined; |
| 11 | var crasher_ptr = &a; | |
| 11 | const crasher_ptr = &a; | |
| 12 | 12 | var crasher_local = crasher_ptr.*; |
| 13 | 13 | const crasher_local_ptr = &crasher_local; |
| 14 | 14 | crasher_local_ptr.lets_crash = 1; |
test/behavior/bugs/13366.zig+2| ... | ... | @@ -18,9 +18,11 @@ test { |
| 18 | 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 19 | 19 | |
| 20 | 20 | var a: u32 = 16; |
| 21 | _ = &a; | |
| 21 | 22 | var reason = .{ .c_import = .{ .a = a } }; |
| 22 | 23 | var block = Block{ |
| 23 | 24 | .reason = &reason, |
| 24 | 25 | }; |
| 26 | _ = &block; | |
| 25 | 27 | try expect(block.reason.?.c_import.a == 16); |
| 26 | 28 | } |
test/behavior/bugs/13714.zig+1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | comptime { |
| 2 | 2 | var image: [1]u8 = undefined; |
| 3 | _ = &image; | |
| 3 | 4 | _ = @shlExact(@as(u16, image[0]), 8); |
| 4 | 5 | } |
test/behavior/bugs/13785.zig+1| ... | ... | @@ -9,5 +9,6 @@ test { |
| 9 | 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 10 | 10 | |
| 11 | 11 | var a: u8 = 0; |
| 12 | _ = &a; | |
| 12 | 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 | 20 | A{ .B = B{ .D = 1 } }, |
| 21 | 21 | A{ .B = B{ .D = 1 } }, |
| 22 | 22 | }; |
| 23 | _ = &as; | |
| 23 | 24 | |
| 24 | 25 | const a = as[0].B; |
| 25 | 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 | 12 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 13 | 13 | |
| 14 | 14 | var union_or_err: anyerror!Union = Union{ .Color = 1234 }; |
| 15 | _ = &union_or_err; | |
| 15 | 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 | 8 | test "allow these dependencies" { |
| 9 | 9 | var a: A = undefined; |
| 10 | 10 | var b: B = undefined; |
| 11 | _ = .{ &a, &b }; | |
| 11 | 12 | if (false) { |
| 12 | 13 | a; |
| 13 | 14 | b; |
test/behavior/bugs/1735.zig+1-1| ... | ... | @@ -45,6 +45,6 @@ test "initialization" { |
| 45 | 45 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 46 | 46 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 47 | 47 | |
| 48 | var t = a.init(); | |
| 48 | const t = a.init(); | |
| 49 | 49 | try std.testing.expect(t.foo.len == 0); |
| 50 | 50 | } |
test/behavior/bugs/2557.zig+1-1| ... | ... | @@ -2,5 +2,5 @@ test { |
| 2 | 2 | var a = if (true) { |
| 3 | 3 | return; |
| 4 | 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 | 3 | var a:i32=2; |
| 4 | 4 | var b=&a; |
| 5 | 5 | b.*=3; |
| 6 | _=&b; | |
| 6 | 7 | } |
test/behavior/bugs/3586.zig+1-1| ... | ... | @@ -12,5 +12,5 @@ test "fixed" { |
| 12 | 12 | var ctr = Container{ |
| 13 | 13 | .params = NoteParams{}, |
| 14 | 14 | }; |
| 15 | _ = ctr; | |
| 15 | _ = &ctr; | |
| 16 | 16 | } |
test/behavior/bugs/4560.zig+1| ... | ... | @@ -11,6 +11,7 @@ test "fixed" { |
| 11 | 11 | .max_distance_from_start_index = 456, |
| 12 | 12 | }, |
| 13 | 13 | }; |
| 14 | _ = &s; | |
| 14 | 15 | try std.testing.expect(s.a == 1); |
| 15 | 16 | try std.testing.expect(s.b.size == 123); |
| 16 | 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 | |
| 7 | 7 | fn getError2() !void { |
| 8 | 8 | var a: u8 = 'c'; |
| 9 | _ = &a; | |
| 9 | 10 | try if (a == 'a') getError() else if (a == 'b') getError() else getError(); |
| 10 | 11 | } |
| 11 | 12 |
test/behavior/bugs/624.zig+1| ... | ... | @@ -25,5 +25,6 @@ test "foo" { |
| 25 | 25 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 26 | 26 | |
| 27 | 27 | var allocator = ContextAllocator{ .n = 10 }; |
| 28 | _ = &allocator; | |
| 28 | 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 | 22 | var prefix_op = PrefixOp{ |
| 23 | 23 | .AddrOf = Value{ .align_expr = 1234 }, |
| 24 | 24 | }; |
| 25 | _ = &prefix_op; | |
| 25 | 26 | if (a) {} else { |
| 26 | 27 | switch (prefix_op) { |
| 27 | 28 | PrefixOp.AddrOf => |addr_of_info| { |
test/behavior/bugs/6781.zig+2-1| ... | ... | @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { |
| 51 | 51 | return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); |
| 52 | 52 | } else { |
| 53 | 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 | } |
| 57 | 58 |
test/behavior/bugs/679.zig+1| ... | ... | @@ -14,5 +14,6 @@ const Element = struct { |
| 14 | 14 | test "false dependency loop in struct definition" { |
| 15 | 15 | const listType = ElementList; |
| 16 | 16 | var x: listType = 42; |
| 17 | _ = &x; | |
| 17 | 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 | 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 7 | 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 8 | 8 | |
| 9 | var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; | |
| 9 | const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; | |
| 10 | 10 | |
| 11 | 11 | var index: u8 = 2; |
| 12 | var slice = u32s[index..index :2]; | |
| 13 | var array_ptr = u32s[2..2 :2]; | |
| 12 | _ = &index; | |
| 13 | const slice = u32s[index..index :2]; | |
| 14 | const array_ptr = u32s[2..2 :2]; | |
| 14 | 15 | const comptime_known_array_value = u32s[2..2 :2].*; |
| 15 | 16 | var runtime_array_value = u32s[2..2 :2].*; |
| 17 | _ = &runtime_array_value; | |
| 16 | 18 | |
| 17 | 19 | try expect(slice[0] == 2); |
| 18 | 20 | try expect(array_ptr[0] == 2); |
test/behavior/bugs/7187.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const expect = std.testing.expect; |
| 5 | 5 | test "miscompilation with bool return type" { |
| 6 | 6 | var x: usize = 1; |
| 7 | 7 | var y: bool = getFalse(); |
| 8 | _ = y; | |
| 8 | _ = .{ &x, &y }; | |
| 9 | 9 | |
| 10 | 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 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 8 | 8 | |
| 9 | 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 | 12 | try expect(x.?.* == 4); |
| 12 | 13 | } |
| 13 | 14 | |
| ... | ... | @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { |
| 19 | 20 | const container = struct { |
| 20 | 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 | 25 | try expect(x.?.* == 4); |
| 24 | 26 | } |
test/behavior/bugs/7325.zig+2| ... | ... | @@ -85,6 +85,7 @@ test { |
| 85 | 85 | var param: ParamType = .{ |
| 86 | 86 | .one_of = .{ .name = "name" }, |
| 87 | 87 | }; |
| 88 | _ = &param; | |
| 88 | 89 | var arg: CallArg = .{ |
| 89 | 90 | .value = .{ |
| 90 | 91 | .literal_enum_value = .{ |
| ... | ... | @@ -92,6 +93,7 @@ test { |
| 92 | 93 | }, |
| 93 | 94 | }, |
| 94 | 95 | }; |
| 96 | _ = &arg; | |
| 95 | 97 | |
| 96 | 98 | const result = try genExpression(arg.value); |
| 97 | 99 | switch (result) { |
test/behavior/bugs/9584.zig+1| ... | ... | @@ -60,6 +60,7 @@ test { |
| 60 | 60 | .g = false, |
| 61 | 61 | .h = false, |
| 62 | 62 | }; |
| 63 | _ = &flags; | |
| 63 | 64 | var x = X{ |
| 64 | 65 | .x = flags, |
| 65 | 66 | }; |
test/behavior/byteswap.zig+8-4| ... | ... | @@ -56,7 +56,8 @@ test "@byteSwap integers" { |
| 56 | 56 | |
| 57 | 57 | fn vector8() !void { |
| 58 | 58 | var v = @Vector(2, u8){ 0x12, 0x13 }; |
| 59 | var result = @byteSwap(v); | |
| 59 | _ = &v; | |
| 60 | const result = @byteSwap(v); | |
| 60 | 61 | try expect(result[0] == 0x12); |
| 61 | 62 | try expect(result[1] == 0x13); |
| 62 | 63 | } |
| ... | ... | @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { |
| 75 | 76 | |
| 76 | 77 | fn vector16() !void { |
| 77 | 78 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 78 | var result = @byteSwap(v); | |
| 79 | _ = &v; | |
| 80 | const result = @byteSwap(v); | |
| 79 | 81 | try expect(result[0] == 0x3412); |
| 80 | 82 | try expect(result[1] == 0x4523); |
| 81 | 83 | } |
| ... | ... | @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { |
| 94 | 96 | |
| 95 | 97 | fn vector24() !void { |
| 96 | 98 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 97 | var result = @byteSwap(v); | |
| 99 | _ = &v; | |
| 100 | const result = @byteSwap(v); | |
| 98 | 101 | try expect(result[0] == 0x563412); |
| 99 | 102 | try expect(result[1] == 0x674523); |
| 100 | 103 | } |
| ... | ... | @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { |
| 113 | 116 | |
| 114 | 117 | fn vector0() !void { |
| 115 | 118 | var v = @Vector(2, u0){ 0, 0 }; |
| 116 | var result = @byteSwap(v); | |
| 119 | _ = &v; | |
| 120 | const result = @byteSwap(v); | |
| 117 | 121 | try expect(result[0] == 0); |
| 118 | 122 | try expect(result[1] == 0); |
| 119 | 123 | } |
test/behavior/call.zig+5| ... | ... | @@ -47,6 +47,7 @@ test "basic invocations" { |
| 47 | 47 | { |
| 48 | 48 | // call of non comptime-known function |
| 49 | 49 | var alias_foo = &foo; |
| 50 | _ = &alias_foo; | |
| 50 | 51 | try expect(@call(.no_async, alias_foo, .{}) == 1234); |
| 51 | 52 | try expect(@call(.never_tail, alias_foo, .{}) == 1234); |
| 52 | 53 | try expect(@call(.never_inline, alias_foo, .{}) == 1234); |
| ... | ... | @@ -66,6 +67,7 @@ test "tuple parameters" { |
| 66 | 67 | }.add; |
| 67 | 68 | var a: i32 = 12; |
| 68 | 69 | var b: i32 = 34; |
| 70 | _ = .{ &a, &b }; | |
| 69 | 71 | try expect(@call(.auto, add, .{ a, 34 }) == 46); |
| 70 | 72 | try expect(@call(.auto, add, .{ 12, b }) == 46); |
| 71 | 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 | 103 | } |
| 102 | 104 | }; |
| 103 | 105 | var runtime = true; |
| 106 | _ = &runtime; | |
| 104 | 107 | try namespace.foo(.{ |
| 105 | 108 | .e = if (!runtime) .a else .b, |
| 106 | 109 | }); |
| ... | ... | @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { |
| 445 | 448 | |
| 446 | 449 | var rt_u16: u16 = 123; |
| 447 | 450 | var rt_u32: u32 = 0x10000222; |
| 451 | _ = .{ &rt_u16, &rt_u32 }; | |
| 448 | 452 | |
| 449 | 453 | try S.f(u8, @intCast(rt_u16)); |
| 450 | 454 | try S.f(u8, @intCast(123)); |
| ... | ... | @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { |
| 470 | 474 | |
| 471 | 475 | fn doTheTest() !void { |
| 472 | 476 | var t = true; |
| 477 | _ = &t; | |
| 473 | 478 | |
| 474 | 479 | // Since the enum literal passes through a runtime conditional here, these can only |
| 475 | 480 | // 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 | 58 | test "implicit cast comptime numbers to any type when the value fits" { |
| 59 | 59 | const a: u64 = 255; |
| 60 | 60 | var b: u8 = a; |
| 61 | _ = &b; | |
| 61 | 62 | try expect(b == 255); |
| 62 | 63 | } |
| 63 | 64 | |
| ... | ... | @@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" { |
| 273 | 274 | |
| 274 | 275 | test "*usize to *void" { |
| 275 | 276 | var i = @as(usize, 0); |
| 276 | var v = @as(*void, @ptrCast(&i)); | |
| 277 | const v: *void = @ptrCast(&i); | |
| 277 | 278 | v.* = {}; |
| 278 | 279 | } |
| 279 | 280 | |
| ... | ... | @@ -391,7 +392,8 @@ test "peer type unsigned int to signed" { |
| 391 | 392 | var w: u31 = 5; |
| 392 | 393 | var x: u8 = 7; |
| 393 | 394 | var y: i32 = -5; |
| 394 | var a = w + y + x; | |
| 395 | _ = .{ &w, &x, &y }; | |
| 396 | const a = w + y + x; | |
| 395 | 397 | try comptime expect(@TypeOf(a) == i32); |
| 396 | 398 | try expect(a == 7); |
| 397 | 399 | } |
| ... | ... | @@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" { |
| 401 | 403 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 402 | 404 | |
| 403 | 405 | var a: [*:0]const u8 = "hello"; |
| 404 | var b: [*c]const u8 = a; | |
| 405 | var c: [*:0]const u8 = b; | |
| 406 | _ = &a; | |
| 407 | const b: [*c]const u8 = a; | |
| 408 | const c: [*:0]const u8 = b; | |
| 406 | 409 | try expect(std.mem.eql(u8, c[0..5], "hello")); |
| 407 | 410 | } |
| 408 | 411 | |
| ... | ... | @@ -609,14 +612,16 @@ test "@intCast on vector" { |
| 609 | 612 | fn doTheTest() !void { |
| 610 | 613 | // Upcast (implicit, equivalent to @intCast) |
| 611 | 614 | var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa }; |
| 612 | var up1 = @as(@Vector(2, u16), up0); | |
| 613 | var up2 = @as(@Vector(2, u32), up0); | |
| 614 | var up3 = @as(@Vector(2, u64), up0); | |
| 615 | _ = &up0; | |
| 616 | const up1 = @as(@Vector(2, u16), up0); | |
| 617 | const up2 = @as(@Vector(2, u32), up0); | |
| 618 | const up3 = @as(@Vector(2, u64), up0); | |
| 615 | 619 | // Downcast (safety-checked) |
| 616 | 620 | var down0 = up3; |
| 617 | var down1 = @as(@Vector(2, u32), @intCast(down0)); | |
| 618 | var down2 = @as(@Vector(2, u16), @intCast(down0)); | |
| 619 | var down3 = @as(@Vector(2, u8), @intCast(down0)); | |
| 621 | _ = &down0; | |
| 622 | const down1 = @as(@Vector(2, u32), @intCast(down0)); | |
| 623 | const down2 = @as(@Vector(2, u16), @intCast(down0)); | |
| 624 | const down3 = @as(@Vector(2, u8), @intCast(down0)); | |
| 620 | 625 | |
| 621 | 626 | try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); |
| 622 | 627 | try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); |
| ... | ... | @@ -629,7 +634,8 @@ test "@intCast on vector" { |
| 629 | 634 | |
| 630 | 635 | fn doTheTestFloat() !void { |
| 631 | 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 | 639 | try expect(wider[0] == 1234.0); |
| 634 | 640 | try expect(wider[1] == 1234.0); |
| 635 | 641 | } |
| ... | ... | @@ -648,7 +654,8 @@ test "@floatCast cast down" { |
| 648 | 654 | |
| 649 | 655 | { |
| 650 | 656 | var double: f64 = 0.001534; |
| 651 | var single = @as(f32, @floatCast(double)); | |
| 657 | _ = &double; | |
| 658 | const single = @as(f32, @floatCast(double)); | |
| 652 | 659 | try expect(single == 0.001534); |
| 653 | 660 | } |
| 654 | 661 | { |
| ... | ... | @@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" { |
| 672 | 679 | Unexpected, |
| 673 | 680 | }; |
| 674 | 681 | var err = Error.SystemResources; |
| 682 | _ = &err; | |
| 675 | 683 | const transformed_err = switch (err) { |
| 676 | 684 | error.FileDescriptorAlreadyPresentInSet => unreachable, |
| 677 | 685 | error.OperationCausesCircularLoop => unreachable, |
| ... | ... | @@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" { |
| 821 | 829 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 822 | 830 | |
| 823 | 831 | var buffer: [5]u8 = "abcde".*; |
| 824 | var buf: anyerror![]const u8 = buffer[0..]; | |
| 832 | const buf: anyerror![]const u8 = buffer[0..]; | |
| 825 | 833 | var b = false; |
| 826 | var y = if (b) &[0]u8{} else buf; | |
| 827 | var z = if (!b) buf else &[0]u8{}; | |
| 834 | _ = &b; | |
| 835 | const y = if (b) &[0]u8{} else buf; | |
| 836 | const z = if (!b) buf else &[0]u8{}; | |
| 828 | 837 | try expect(mem.eql(u8, "abcde", y catch unreachable)); |
| 829 | 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 | 844 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 836 | 845 | |
| 837 | 846 | var buffer: [5]u8 = "abcde".*; |
| 838 | var buf: []const u8 = buffer[0..]; | |
| 847 | const buf: []const u8 = buffer[0..]; | |
| 839 | 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 | 851 | try expect(mem.eql(u8, "abcde", y)); |
| 842 | 852 | } |
| 843 | 853 | |
| ... | ... | @@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" { |
| 846 | 856 | |
| 847 | 857 | var array = [4:99]i32{ 1, 2, 3, 4 }; |
| 848 | 858 | var dest: [*]i32 = undefined; |
| 859 | _ = &dest; | |
| 849 | 860 | try expect(@TypeOf(&array, dest) == [*]i32); |
| 850 | 861 | try expect(@TypeOf(dest, &array) == [*]i32); |
| 851 | 862 | } |
| ... | ... | @@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" { |
| 879 | 890 | const S = struct { |
| 880 | 891 | fn doTheTest() !void { |
| 881 | 892 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 882 | var slice: [:0]i32 = &array; | |
| 883 | var dest: []i32 = slice; | |
| 893 | const slice: [:0]i32 = &array; | |
| 894 | const dest: []i32 = slice; | |
| 884 | 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 | 906 | const S = struct { |
| 896 | 907 | fn doTheTest() !void { |
| 897 | 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 | 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 | 922 | const S = struct { |
| 911 | 923 | fn doTheTest() !void { |
| 912 | 924 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 913 | var dest: *[4]i32 = &array; | |
| 925 | const dest: *[4]i32 = &array; | |
| 914 | 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 | 937 | const S = struct { |
| 926 | 938 | fn doTheTest() !void { |
| 927 | 939 | var array = [4:99]i32{ 1, 2, 3, 4 }; |
| 928 | var dest: [*]i32 = &array; | |
| 940 | const dest: [*]i32 = &array; | |
| 929 | 941 | try expect(dest[0] == 1); |
| 930 | 942 | try expect(dest[1] == 2); |
| 931 | 943 | try expect(dest[2] == 3); |
| ... | ... | @@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" { |
| 945 | 957 | const S = struct { |
| 946 | 958 | fn doTheTest() !void { |
| 947 | 959 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 948 | var slice: [:0]i32 = &array; | |
| 949 | var dest: [*:0]i32 = slice; | |
| 960 | const slice: [:0]i32 = &array; | |
| 961 | const dest: [*:0]i32 = slice; | |
| 950 | 962 | try expect(dest[0] == 1); |
| 951 | 963 | try expect(dest[1] == 2); |
| 952 | 964 | try expect(dest[2] == 3); |
| ... | ... | @@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" { |
| 998 | 1010 | |
| 999 | 1011 | test "variable initialization uses result locations properly with regards to the type" { |
| 1000 | 1012 | var b = true; |
| 1013 | _ = &b; | |
| 1001 | 1014 | const x: i32 = if (b) 1 else 2; |
| 1002 | 1015 | try expect(x == 1); |
| 1003 | 1016 | } |
| ... | ... | @@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { |
| 1025 | 1038 | |
| 1026 | 1039 | var array: [4:0]u8 = undefined; |
| 1027 | 1040 | 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 | 1042 | try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); |
| 1030 | 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 | 1055 | var array: [4]u8 = undefined; |
| 1043 | 1056 | var const_ptr: [*]const u8 = undefined; |
| 1044 | 1057 | var ptr: [*]u8 = undefined; |
| 1058 | _ = .{ &const_ptr, &ptr }; | |
| 1045 | 1059 | |
| 1046 | 1060 | try comptime expect(@TypeOf(&array, ptr) == [*]u8); |
| 1047 | 1061 | try comptime expect(@TypeOf(ptr, &array) == [*]u8); |
| ... | ... | @@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" { |
| 1090 | 1104 | |
| 1091 | 1105 | var a = [_]u8{ 3, 2, 1 }; |
| 1092 | 1106 | var runtime_zero: usize = 0; |
| 1107 | _ = &runtime_zero; | |
| 1093 | 1108 | incrementVoidPtrArray(a[runtime_zero..].ptr, 3); |
| 1094 | 1109 | try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); |
| 1095 | 1110 | } |
| ... | ... | @@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" { |
| 1151 | 1166 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1152 | 1167 | |
| 1153 | 1168 | var a: u32 = 1; |
| 1154 | var ptr: *align(@alignOf(u32)) anyopaque = &a; | |
| 1155 | var b: *u32 = @as(*u32, @ptrCast(ptr)); | |
| 1169 | const ptr: *align(@alignOf(u32)) anyopaque = &a; | |
| 1170 | const b: *u32 = @as(*u32, @ptrCast(ptr)); | |
| 1156 | 1171 | try expect(b.* == 1); |
| 1157 | var ptr2: ?*align(@alignOf(u32)) anyopaque = &a; | |
| 1158 | var c: *u32 = @as(*u32, @ptrCast(ptr2.?)); | |
| 1172 | const ptr2: ?*align(@alignOf(u32)) anyopaque = &a; | |
| 1173 | const c: *u32 = @as(*u32, @ptrCast(ptr2.?)); | |
| 1159 | 1174 | try expect(c.* == 1); |
| 1160 | 1175 | } |
| 1161 | 1176 | |
| ... | ... | @@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" { |
| 1264 | 1279 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1265 | 1280 | |
| 1266 | 1281 | var x = @as(anyerror![]const u8, &[0]u8{}); |
| 1282 | _ = &x; | |
| 1267 | 1283 | try expect((x catch unreachable).len == 0); |
| 1268 | 1284 | } |
| 1269 | 1285 | |
| ... | ... | @@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" { |
| 1274 | 1290 | } |
| 1275 | 1291 | test "cast from array reference to fn: runtime fn ptr" { |
| 1276 | 1292 | var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); |
| 1293 | _ = &f; | |
| 1277 | 1294 | try expect(@intFromPtr(f) == @intFromPtr(&global_array)); |
| 1278 | 1295 | } |
| 1279 | 1296 | |
| ... | ... | @@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" { |
| 1285 | 1302 | const S = struct { |
| 1286 | 1303 | fn doTheTest() !void { |
| 1287 | 1304 | var a = "Hello"; |
| 1288 | var b: ?[]const u8 = a; | |
| 1305 | _ = &a; | |
| 1306 | const b: ?[]const u8 = a; | |
| 1289 | 1307 | try expect(mem.eql(u8, b.?, "Hello")); |
| 1290 | 1308 | } |
| 1291 | 1309 | }; |
| ... | ... | @@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" { |
| 1318 | 1336 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1319 | 1337 | |
| 1320 | 1338 | var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; |
| 1339 | _ = &foo; | |
| 1321 | 1340 | try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); |
| 1322 | 1341 | } |
| 1323 | 1342 | |
| 1324 | 1343 | test "cast between *[N]void and []void" { |
| 1325 | 1344 | var a: [4]void = undefined; |
| 1326 | var b: []void = &a; | |
| 1345 | const b: []void = &a; | |
| 1327 | 1346 | try expect(b.len == 4); |
| 1328 | 1347 | } |
| 1329 | 1348 | |
| ... | ... | @@ -1351,6 +1370,7 @@ test "cast f16 to wider types" { |
| 1351 | 1370 | const S = struct { |
| 1352 | 1371 | fn doTheTest() !void { |
| 1353 | 1372 | var x: f16 = 1234.0; |
| 1373 | _ = &x; | |
| 1354 | 1374 | try expect(@as(f32, 1234.0) == x); |
| 1355 | 1375 | try expect(@as(f64, 1234.0) == x); |
| 1356 | 1376 | try expect(@as(f128, 1234.0) == x); |
| ... | ... | @@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" { |
| 1370 | 1390 | const S = struct { |
| 1371 | 1391 | fn doTheTest() !void { |
| 1372 | 1392 | var x: f128 = 1234.0; |
| 1393 | _ = &x; | |
| 1373 | 1394 | try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x))); |
| 1374 | 1395 | try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x))); |
| 1375 | 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 | 1425 | const S = struct { |
| 1405 | 1426 | fn doTheTest() !void { |
| 1406 | 1427 | var cond = true; |
| 1428 | _ = &cond; | |
| 1407 | 1429 | const value: i32 = if (cond) smallBoi() else bigBoi(); |
| 1408 | 1430 | try expect(value == 123); |
| 1409 | 1431 | } |
| ... | ... | @@ -1424,7 +1446,8 @@ test "cast compatible optional types" { |
| 1424 | 1446 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1425 | 1447 | |
| 1426 | 1448 | var a: ?[:0]const u8 = null; |
| 1427 | var b: ?[]const u8 = a; | |
| 1449 | _ = &a; | |
| 1450 | const b: ?[]const u8 = a; | |
| 1428 | 1451 | try expect(b == null); |
| 1429 | 1452 | } |
| 1430 | 1453 | |
| ... | ... | @@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" { |
| 1434 | 1457 | |
| 1435 | 1458 | const a = @as([*]u8, undefined)[0..0]; |
| 1436 | 1459 | var b: error{a}![]const u8 = a; |
| 1460 | _ = &b; | |
| 1437 | 1461 | const s = try b; |
| 1438 | 1462 | try expect(s.len == 0); |
| 1439 | 1463 | } |
| ... | ... | @@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" { |
| 1442 | 1466 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1443 | 1467 | |
| 1444 | 1468 | var x: []i32 = &.{}; |
| 1469 | _ = &x; | |
| 1445 | 1470 | try expect(x.len == 0); |
| 1446 | 1471 | } |
| 1447 | 1472 | |
| ... | ... | @@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" { |
| 1466 | 1491 | else => @compileError("unreachable"), |
| 1467 | 1492 | }; |
| 1468 | 1493 | var f1: F = 12.34; |
| 1469 | var f2: *c_longdouble = &f1; | |
| 1494 | const f2: *c_longdouble = &f1; | |
| 1470 | 1495 | f2.* += 1; |
| 1471 | 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 | 1532 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1508 | 1533 | |
| 1509 | 1534 | var a: [:0]const u8 = "foo"; |
| 1510 | var b: [*c]const u8 = a; | |
| 1511 | var c = std.mem.span(b); | |
| 1535 | _ = &a; | |
| 1536 | const b: [*c]const u8 = a; | |
| 1537 | const c = std.mem.span(b); | |
| 1512 | 1538 | try expect(c.len == a.len); |
| 1513 | 1539 | try expect(c.ptr == a.ptr); |
| 1514 | 1540 | } |
| ... | ... | @@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" { |
| 1544 | 1570 | |
| 1545 | 1571 | test "peer type resolution forms error union" { |
| 1546 | 1572 | var foo: i32 = 123; |
| 1573 | _ = &foo; | |
| 1547 | 1574 | const result = if (foo < 0) switch (-foo) { |
| 1548 | 1575 | 0 => unreachable, |
| 1549 | 1576 | 42 => error.AccessDenied, |
| ... | ... | @@ -1561,7 +1588,7 @@ test "@constCast without a result location" { |
| 1561 | 1588 | |
| 1562 | 1589 | test "@volatileCast without a result location" { |
| 1563 | 1590 | var x: i32 = 1234; |
| 1564 | var y: *volatile i32 = &x; | |
| 1591 | const y: *volatile i32 = &x; | |
| 1565 | 1592 | const z = @volatileCast(y); |
| 1566 | 1593 | try expect(@TypeOf(z) == *i32); |
| 1567 | 1594 | try expect(z.* == 1234); |
| ... | ... | @@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" |
| 1585 | 1612 | fn doTheTest(comptime T: type, comptime s: T) !void { |
| 1586 | 1613 | var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); |
| 1587 | 1614 | var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); |
| 1615 | _ = .{ &a, &b }; | |
| 1588 | 1616 | comptime assert(@TypeOf(a, b) == []const T); |
| 1589 | 1617 | comptime assert(@TypeOf(b, a) == []const T); |
| 1590 | 1618 | |
| 1591 | 1619 | var t = true; |
| 1620 | _ = &t; | |
| 1592 | 1621 | const r1 = if (t) a else b; |
| 1593 | 1622 | const r2 = if (t) b else a; |
| 1594 | 1623 | |
| ... | ... | @@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" { |
| 1611 | 1640 | |
| 1612 | 1641 | const i: u8 = 100; |
| 1613 | 1642 | var f: f32 = 1.234; |
| 1643 | _ = &f; | |
| 1614 | 1644 | comptime assert(@TypeOf(i, f) == f32); |
| 1615 | 1645 | comptime assert(@TypeOf(f, i) == f32); |
| 1616 | 1646 | |
| 1617 | 1647 | var t = true; |
| 1648 | _ = &t; | |
| 1618 | 1649 | const r1 = if (t) i else f; |
| 1619 | 1650 | const r2 = if (t) f else i; |
| 1620 | 1651 | |
| ... | ... | @@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" { |
| 1631 | 1662 | |
| 1632 | 1663 | var a: [2:0]u32 = .{ 0, 1 }; |
| 1633 | 1664 | var b: [2:0]u32 = .{ 2, 3 }; |
| 1665 | _ = .{ &a, &b }; | |
| 1634 | 1666 | comptime assert(@TypeOf(a, b) == [2:0]u32); |
| 1635 | 1667 | comptime assert(@TypeOf(b, a) == [2:0]u32); |
| 1636 | 1668 | |
| 1637 | 1669 | var t = true; |
| 1670 | _ = &t; | |
| 1638 | 1671 | const r1 = if (t) a else b; |
| 1639 | 1672 | const r2 = if (t) b else a; |
| 1640 | 1673 | |
| ... | ... | @@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" { |
| 1651 | 1684 | |
| 1652 | 1685 | var a: [2:0]u32 = .{ 0, 1 }; |
| 1653 | 1686 | var b: [2]u32 = .{ 2, 3 }; |
| 1687 | _ = .{ &a, &b }; | |
| 1654 | 1688 | comptime assert(@TypeOf(a, b) == [2]u32); |
| 1655 | 1689 | comptime assert(@TypeOf(b, a) == [2]u32); |
| 1656 | 1690 | |
| 1657 | 1691 | var t = true; |
| 1692 | _ = &t; | |
| 1658 | 1693 | const r1 = if (t) a else b; |
| 1659 | 1694 | const r2 = if (t) b else a; |
| 1660 | 1695 | |
| ... | ... | @@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" { |
| 1671 | 1706 | |
| 1672 | 1707 | var arr: [2]u32 = .{ 0, 1 }; |
| 1673 | 1708 | var vec: @Vector(2, u32) = .{ 2, 3 }; |
| 1709 | _ = .{ &arr, &vec }; | |
| 1674 | 1710 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u32)); |
| 1675 | 1711 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u32)); |
| 1676 | 1712 | |
| 1677 | 1713 | var t = true; |
| 1714 | _ = &t; | |
| 1678 | 1715 | const r1 = if (t) arr else vec; |
| 1679 | 1716 | const r2 = if (t) vec else arr; |
| 1680 | 1717 | |
| ... | ... | @@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger |
| 1694 | 1731 | |
| 1695 | 1732 | var arr: [2]u8 = .{ 0, 1 }; |
| 1696 | 1733 | var vec: @Vector(2, u64) = .{ 2, 3 }; |
| 1734 | _ = .{ &arr, &vec }; | |
| 1697 | 1735 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u64)); |
| 1698 | 1736 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u64)); |
| 1699 | 1737 | |
| 1700 | 1738 | var t = true; |
| 1739 | _ = &t; | |
| 1701 | 1740 | const r1 = if (t) arr else vec; |
| 1702 | 1741 | const r2 = if (t) vec else arr; |
| 1703 | 1742 | |
| ... | ... | @@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" { |
| 1715 | 1754 | const E = error{Foo}; |
| 1716 | 1755 | var a: E!*u8 = error.Foo; |
| 1717 | 1756 | var b: ?*u8 = null; |
| 1757 | _ = .{ &a, &b }; | |
| 1718 | 1758 | comptime assert(@TypeOf(a, b) == E!?*u8); |
| 1719 | 1759 | comptime assert(@TypeOf(b, a) == E!?*u8); |
| 1720 | 1760 | |
| 1721 | 1761 | var t = true; |
| 1762 | _ = &t; | |
| 1722 | 1763 | const r1 = if (t) a else b; |
| 1723 | 1764 | const r2 = if (t) b else a; |
| 1724 | 1765 | |
| ... | ... | @@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" { |
| 1734 | 1775 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1735 | 1776 | |
| 1736 | 1777 | var a: [*c]c_int = 0x1000; |
| 1778 | _ = &a; | |
| 1737 | 1779 | const b = null; |
| 1738 | 1780 | comptime assert(@TypeOf(a, b) == [*c]c_int); |
| 1739 | 1781 | comptime assert(@TypeOf(b, a) == [*c]c_int); |
| 1740 | 1782 | |
| 1741 | 1783 | var t = true; |
| 1784 | _ = &t; | |
| 1742 | 1785 | const r1 = if (t) a else b; |
| 1743 | 1786 | const r2 = if (t) b else a; |
| 1744 | 1787 | |
| ... | ... | @@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional |
| 1755 | 1798 | |
| 1756 | 1799 | const E = error{Foo}; |
| 1757 | 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 | 1802 | var c: ?[*:0]u8 = null; |
| 1803 | _ = .{ &a, &b, &c }; | |
| 1760 | 1804 | comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); |
| 1761 | 1805 | comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); |
| 1762 | 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 | 1809 | comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8); |
| 1766 | 1810 | |
| 1767 | 1811 | var x: u8 = 0; |
| 1812 | _ = &x; | |
| 1768 | 1813 | const r1 = switch (x) { |
| 1769 | 1814 | 0 => a, |
| 1770 | 1815 | 1 => b, |
| ... | ... | @@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" { |
| 1797 | 1842 | |
| 1798 | 1843 | var a: ?@Vector(3, u32) = .{ 0, 1, 2 }; |
| 1799 | 1844 | var b: @Vector(3, u32) = .{ 3, 4, 5 }; |
| 1845 | _ = .{ &a, &b }; | |
| 1800 | 1846 | comptime assert(@TypeOf(a, b) == ?@Vector(3, u32)); |
| 1801 | 1847 | comptime assert(@TypeOf(b, a) == ?@Vector(3, u32)); |
| 1802 | 1848 | |
| 1803 | 1849 | var t = true; |
| 1850 | _ = &t; | |
| 1804 | 1851 | const r1 = if (t) a else b; |
| 1805 | 1852 | const r2 = if (t) b else a; |
| 1806 | 1853 | |
| ... | ... | @@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" { |
| 1816 | 1863 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1817 | 1864 | |
| 1818 | 1865 | var a: ?i32 = 42; |
| 1866 | _ = &a; | |
| 1819 | 1867 | const b: comptime_int = 50; |
| 1820 | 1868 | comptime assert(@TypeOf(a, b) == ?i32); |
| 1821 | 1869 | comptime assert(@TypeOf(b, a) == ?i32); |
| 1822 | 1870 | |
| 1823 | 1871 | var t = true; |
| 1872 | _ = &t; | |
| 1824 | 1873 | const r1 = if (t) a else b; |
| 1825 | 1874 | const r2 = if (t) b else a; |
| 1826 | 1875 | |
| ... | ... | @@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" { |
| 1836 | 1885 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1837 | 1886 | |
| 1838 | 1887 | var arr: [3]i32 = .{ 1, 2, 3 }; |
| 1888 | _ = &arr; | |
| 1839 | 1889 | const tup = .{ 4, 5, 6 }; |
| 1840 | 1890 | |
| 1841 | 1891 | comptime assert(@TypeOf(arr, tup) == [3]i32); |
| 1842 | 1892 | comptime assert(@TypeOf(tup, arr) == [3]i32); |
| 1843 | 1893 | |
| 1844 | 1894 | var t = true; |
| 1895 | _ = &t; | |
| 1845 | 1896 | const r1 = if (t) arr else tup; |
| 1846 | 1897 | const r2 = if (t) tup else arr; |
| 1847 | 1898 | |
| ... | ... | @@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" { |
| 1858 | 1909 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1859 | 1910 | |
| 1860 | 1911 | var vec: @Vector(3, i32) = .{ 1, 2, 3 }; |
| 1912 | _ = &vec; | |
| 1861 | 1913 | const tup = .{ 4, 5, 6 }; |
| 1862 | 1914 | |
| 1863 | 1915 | comptime assert(@TypeOf(vec, tup) == @Vector(3, i32)); |
| 1864 | 1916 | comptime assert(@TypeOf(tup, vec) == @Vector(3, i32)); |
| 1865 | 1917 | |
| 1866 | 1918 | var t = true; |
| 1919 | _ = &t; | |
| 1867 | 1920 | const r1 = if (t) vec else tup; |
| 1868 | 1921 | const r2 = if (t) tup else vec; |
| 1869 | 1922 | |
| ... | ... | @@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" { |
| 1881 | 1934 | |
| 1882 | 1935 | var vec: @Vector(2, i8) = .{ 10, 20 }; |
| 1883 | 1936 | var arr: [2]i8 = .{ 30, 40 }; |
| 1937 | _ = .{ &vec, &arr }; | |
| 1884 | 1938 | const tup = .{ 50, 60 }; |
| 1885 | 1939 | |
| 1886 | 1940 | comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8)); |
| ... | ... | @@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" { |
| 1891 | 1945 | comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8)); |
| 1892 | 1946 | |
| 1893 | 1947 | var x: u8 = 0; |
| 1948 | _ = &x; | |
| 1894 | 1949 | const r1 = switch (x) { |
| 1895 | 1950 | 0 => vec, |
| 1896 | 1951 | 1 => arr, |
| ... | ... | @@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" { |
| 1921 | 1976 | |
| 1922 | 1977 | var a: [:0]const u8 = "Hello"; |
| 1923 | 1978 | var b = &.{}; |
| 1979 | _ = .{ &a, &b }; | |
| 1924 | 1980 | |
| 1925 | 1981 | comptime assert(@TypeOf(a, b) == []const u8); |
| 1926 | 1982 | comptime assert(@TypeOf(b, a) == []const u8); |
| 1927 | 1983 | |
| 1928 | 1984 | var t = true; |
| 1985 | _ = &t; | |
| 1929 | 1986 | const r1 = if (t) a else b; |
| 1930 | 1987 | const r2 = if (t) b else a; |
| 1931 | 1988 | |
| ... | ... | @@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" { |
| 1940 | 1997 | |
| 1941 | 1998 | var a: [:0]const u8 = "Hello"; |
| 1942 | 1999 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; |
| 2000 | _ = .{ &a, &b }; | |
| 1943 | 2001 | |
| 1944 | 2002 | comptime assert(@TypeOf(a, b) == []const u8); |
| 1945 | 2003 | comptime assert(@TypeOf(b, a) == []const u8); |
| 1946 | 2004 | |
| 1947 | 2005 | var t = true; |
| 2006 | _ = &t; | |
| 1948 | 2007 | const r1 = if (t) a else b; |
| 1949 | 2008 | const r2 = if (t) b else a; |
| 1950 | 2009 | |
| ... | ... | @@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" { |
| 1959 | 2018 | |
| 1960 | 2019 | var a: ?[:0]const u8 = null; |
| 1961 | 2020 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; |
| 2021 | _ = .{ &a, &b }; | |
| 1962 | 2022 | |
| 1963 | 2023 | comptime assert(@TypeOf(a, b) == ?[]const u8); |
| 1964 | 2024 | comptime assert(@TypeOf(b, a) == ?[]const u8); |
| 1965 | 2025 | |
| 1966 | 2026 | var t = true; |
| 2027 | _ = &t; | |
| 1967 | 2028 | const r1 = if (t) a else b; |
| 1968 | 2029 | const r2 = if (t) b else a; |
| 1969 | 2030 | |
| ... | ... | @@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" { |
| 1986 | 2047 | @as([*]u8, &buf), |
| 1987 | 2048 | @as(*const [5]u8, "foo-4"), |
| 1988 | 2049 | }; |
| 2050 | _ = &vals; | |
| 1989 | 2051 | |
| 1990 | 2052 | // Check every possible permutation of types in @TypeOf |
| 1991 | 2053 | @setEvalBranchQuota(5000); |
| ... | ... | @@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" { |
| 2015 | 2077 | comptime assert(perms == 5 * 4 * 3 * 2 * 1); |
| 2016 | 2078 | |
| 2017 | 2079 | var x: u8 = 0; |
| 2080 | _ = &x; | |
| 2018 | 2081 | inline for (0..5) |i| { |
| 2019 | 2082 | const r = switch (x) { |
| 2020 | 2083 | 0 => vals[i], |
| ... | ... | @@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" { |
| 2057 | 2120 | } |
| 2058 | 2121 | |
| 2059 | 2122 | var t = true; |
| 2123 | _ = &t; | |
| 2060 | 2124 | const r1 = if (t) a else b; |
| 2061 | 2125 | const r2 = if (t) b else a; |
| 2062 | 2126 | |
| ... | ... | @@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" { |
| 2074 | 2138 | |
| 2075 | 2139 | var buf = "hello".*; |
| 2076 | 2140 | |
| 2077 | var a: [*c]u8 = &buf; | |
| 2141 | const a: [*c]u8 = &buf; | |
| 2078 | 2142 | var b: [*:0]const u8 = "world"; |
| 2143 | _ = &b; | |
| 2079 | 2144 | |
| 2080 | 2145 | comptime assert(@TypeOf(a, b) == [*c]const u8); |
| 2081 | 2146 | comptime assert(@TypeOf(b, a) == [*c]const u8); |
| 2082 | 2147 | |
| 2083 | 2148 | var t = true; |
| 2149 | _ = &t; | |
| 2084 | 2150 | const r1 = if (t) a else b; |
| 2085 | 2151 | const r2 = if (t) b else a; |
| 2086 | 2152 | |
| ... | ... | @@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" { |
| 2097 | 2163 | var buf_b align(4) = "bar".*; |
| 2098 | 2164 | var buf_c align(4) = "baz".*; |
| 2099 | 2165 | |
| 2100 | var a: [*:0]align(4) const u8 = &buf_a; | |
| 2101 | var b: *align(2) volatile [3:0]u8 = &buf_b; | |
| 2102 | var c: [*:0]align(4) u8 = &buf_c; | |
| 2166 | const a: [*:0]align(4) const u8 = &buf_a; | |
| 2167 | const b: *align(2) volatile [3:0]u8 = &buf_b; | |
| 2168 | const c: [*:0]align(4) u8 = &buf_c; | |
| 2103 | 2169 | |
| 2104 | 2170 | comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8); |
| 2105 | 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 | 2175 | comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8); |
| 2110 | 2176 | |
| 2111 | 2177 | var x: u8 = 0; |
| 2178 | _ = &x; | |
| 2112 | 2179 | const r1 = switch (x) { |
| 2113 | 2180 | 0 => a, |
| 2114 | 2181 | 1 => b, |
| ... | ... | @@ -2254,6 +2321,7 @@ test "@floatCast on vector" { |
| 2254 | 2321 | const S = struct { |
| 2255 | 2322 | fn doTheTest() !void { |
| 2256 | 2323 | var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 }; |
| 2324 | _ = &a; | |
| 2257 | 2325 | const b: @Vector(3, f32) = @floatCast(a); |
| 2258 | 2326 | try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b); |
| 2259 | 2327 | } |
| ... | ... | @@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" { |
| 2274 | 2342 | const S = struct { |
| 2275 | 2343 | fn doTheTest() !void { |
| 2276 | 2344 | var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 }; |
| 2345 | _ = &a; | |
| 2277 | 2346 | const b: @Vector(3, *anyopaque) = @ptrFromInt(a); |
| 2278 | 2347 | try expectEqual(@Vector(3, *anyopaque){ |
| 2279 | 2348 | @ptrFromInt(0x1000), |
| ... | ... | @@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" { |
| 2302 | 2371 | @ptrFromInt(0x2000), |
| 2303 | 2372 | @ptrFromInt(0x3000), |
| 2304 | 2373 | }; |
| 2374 | _ = &a; | |
| 2305 | 2375 | const b: @Vector(3, usize) = @intFromPtr(a); |
| 2306 | 2376 | try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b); |
| 2307 | 2377 | } |
| ... | ... | @@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" { |
| 2322 | 2392 | const S = struct { |
| 2323 | 2393 | fn doTheTest() !void { |
| 2324 | 2394 | var a: @Vector(3, u32) = .{ 10, 20, 30 }; |
| 2395 | _ = &a; | |
| 2325 | 2396 | const b: @Vector(3, f32) = @floatFromInt(a); |
| 2326 | 2397 | try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b); |
| 2327 | 2398 | } |
| ... | ... | @@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" { |
| 2342 | 2413 | const S = struct { |
| 2343 | 2414 | fn doTheTest() !void { |
| 2344 | 2415 | var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 }; |
| 2416 | _ = &a; | |
| 2345 | 2417 | const b: @Vector(3, u32) = @intFromFloat(a); |
| 2346 | 2418 | try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b); |
| 2347 | 2419 | } |
| ... | ... | @@ -2362,6 +2434,7 @@ test "@intFromBool on vector" { |
| 2362 | 2434 | const S = struct { |
| 2363 | 2435 | fn doTheTest() !void { |
| 2364 | 2436 | var a: @Vector(3, bool) = .{ false, true, false }; |
| 2437 | _ = &a; | |
| 2365 | 2438 | const b: @Vector(3, u1) = @intFromBool(a); |
| 2366 | 2439 | try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b); |
| 2367 | 2440 | } |
| ... | ... | @@ -2385,7 +2458,8 @@ test "15-bit int to float" { |
| 2385 | 2458 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 2386 | 2459 | |
| 2387 | 2460 | var a: u15 = 42; |
| 2388 | var b: f32 = @floatFromInt(a); | |
| 2461 | _ = &a; | |
| 2462 | const b: f32 = @floatFromInt(a); | |
| 2389 | 2463 | try expect(b == 42.0); |
| 2390 | 2464 | } |
| 2391 | 2465 | |
| ... | ... | @@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" { |
| 2417 | 2491 | const T = *const ?E!struct { x: ?*const E!?u8 }; |
| 2418 | 2492 | |
| 2419 | 2493 | var val: T = &.{ .x = &@truncate(0x1234) }; |
| 2494 | _ = &val; | |
| 2420 | 2495 | |
| 2421 | 2496 | const struct_val = val.*.? catch unreachable; |
| 2422 | 2497 | const int_val = (struct_val.x.?.* catch unreachable).?; |
| ... | ... | @@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" { |
| 2439 | 2514 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 2440 | 2515 | |
| 2441 | 2516 | var x: @Vector(4, i32) = .{ 1, 2, 3, 4 }; |
| 2517 | _ = &x; | |
| 2442 | 2518 | const y: @Vector(4, i8) = @intCast(x); |
| 2443 | 2519 | |
| 2444 | 2520 | try expect(y[0] == 1); |
test/behavior/cast_int.zig+17-2| ... | ... | @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { |
| 12 | 12 | |
| 13 | 13 | var x: u128 = maxInt(u128); |
| 14 | 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 | 17 | try expect(z == 0xff); |
| 17 | 18 | } |
| 18 | 19 | |
| ... | ... | @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { |
| 23 | 24 | |
| 24 | 25 | var x: i8 = -5; |
| 25 | 26 | var y: i32 = -5; |
| 27 | _ = .{ &x, &y }; | |
| 26 | 28 | try expect(y == x); |
| 27 | 29 | |
| 28 | 30 | var x2: i32 = -5; |
| 29 | 31 | var y2: i8 = -5; |
| 32 | _ = .{ &x2, &y2 }; | |
| 30 | 33 | try expect(y2 == @as(i8, @intCast(x2))); |
| 31 | 34 | } |
| 32 | 35 | |
| 33 | 36 | test "coerce non byte-sized integers accross 32bits boundary" { |
| 34 | 37 | { |
| 35 | 38 | var v: u21 = 6417; |
| 39 | _ = &v; | |
| 36 | 40 | const a: u32 = v; |
| 37 | 41 | const b: u64 = v; |
| 38 | 42 | const c: u64 = a; |
| 39 | 43 | var w: u64 = 0x1234567812345678; |
| 44 | _ = &w; | |
| 40 | 45 | const d: u21 = @truncate(w); |
| 41 | 46 | const e: u60 = d; |
| 42 | 47 | try expectEqual(@as(u32, 6417), a); |
| ... | ... | @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 48 | 53 | |
| 49 | 54 | { |
| 50 | 55 | var v: u10 = 234; |
| 56 | _ = &v; | |
| 51 | 57 | const a: u32 = v; |
| 52 | 58 | const b: u64 = v; |
| 53 | 59 | const c: u64 = a; |
| 54 | 60 | var w: u64 = 0x1234567812345678; |
| 61 | _ = &w; | |
| 55 | 62 | const d: u10 = @truncate(w); |
| 56 | 63 | const e: u60 = d; |
| 57 | 64 | try expectEqual(@as(u32, 234), a); |
| ... | ... | @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 62 | 69 | } |
| 63 | 70 | { |
| 64 | 71 | var v: u7 = 11; |
| 72 | _ = &v; | |
| 65 | 73 | const a: u32 = v; |
| 66 | 74 | const b: u64 = v; |
| 67 | 75 | const c: u64 = a; |
| 68 | 76 | var w: u64 = 0x1234567812345678; |
| 77 | _ = &w; | |
| 69 | 78 | const d: u7 = @truncate(w); |
| 70 | 79 | const e: u60 = d; |
| 71 | 80 | try expectEqual(@as(u32, 11), a); |
| ... | ... | @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 77 | 86 | |
| 78 | 87 | { |
| 79 | 88 | var v: i21 = -6417; |
| 89 | _ = &v; | |
| 80 | 90 | const a: i32 = v; |
| 81 | 91 | const b: i64 = v; |
| 82 | 92 | const c: i64 = a; |
| 83 | 93 | var w: i64 = -12345; |
| 94 | _ = &w; | |
| 84 | 95 | const d: i21 = @intCast(w); |
| 85 | 96 | const e: i60 = d; |
| 86 | 97 | try expectEqual(@as(i32, -6417), a); |
| ... | ... | @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 92 | 103 | |
| 93 | 104 | { |
| 94 | 105 | var v: i10 = -234; |
| 106 | _ = &v; | |
| 95 | 107 | const a: i32 = v; |
| 96 | 108 | const b: i64 = v; |
| 97 | 109 | const c: i64 = a; |
| 98 | 110 | var w: i64 = -456; |
| 111 | _ = &w; | |
| 99 | 112 | const d: i10 = @intCast(w); |
| 100 | 113 | const e: i60 = d; |
| 101 | 114 | try expectEqual(@as(i32, -234), a); |
| ... | ... | @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 106 | 119 | } |
| 107 | 120 | { |
| 108 | 121 | var v: i7 = -11; |
| 122 | _ = &v; | |
| 109 | 123 | const a: i32 = v; |
| 110 | 124 | const b: i64 = v; |
| 111 | 125 | const c: i64 = a; |
| 112 | 126 | var w: i64 = -42; |
| 127 | _ = &w; | |
| 113 | 128 | const d: i7 = @intCast(w); |
| 114 | 129 | const e: i60 = d; |
| 115 | 130 | try expectEqual(@as(i32, -11), a); |
| ... | ... | @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { |
| 152 | 167 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 153 | 168 | |
| 154 | 169 | // 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 | 171 | try expect(opt.?.type == .PAWN); |
| 157 | 172 | try expect(opt.?.color == .BLACK); |
| 158 | 173 |
test/behavior/comptime_memory.zig+1-1| ... | ... | @@ -280,7 +280,7 @@ test "dance on linker values" { |
| 280 | 280 | if (ptr_size > @sizeOf(Bits)) |
| 281 | 281 | try doTypePunBitsTest(&weird_ptr[1]); |
| 282 | 282 | |
| 283 | var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); | |
| 283 | const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr); | |
| 284 | 284 | |
| 285 | 285 | var rebuilt_bytes: [ptr_size]u8 = undefined; |
| 286 | 286 | var i: usize = 0; |
test/behavior/destructure.zig+4| ... | ... | @@ -7,6 +7,7 @@ test "simple destructure" { |
| 7 | 7 | fn doTheTest() !void { |
| 8 | 8 | var x: u32 = undefined; |
| 9 | 9 | x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; |
| 10 | _ = &z; | |
| 10 | 11 | |
| 11 | 12 | comptime assert(@TypeOf(y) == u16); |
| 12 | 13 | |
| ... | ... | @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { |
| 25 | 26 | fn doTheTest() void { |
| 26 | 27 | comptime var x: f32 = undefined; |
| 27 | 28 | comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var |
| 29 | _ = &z; | |
| 28 | 30 | |
| 29 | 31 | comptime assert(@TypeOf(y) == comptime_int); |
| 30 | 32 | comptime assert(@TypeOf(z) == comptime_int); |
| ... | ... | @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { |
| 112 | 114 | test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { |
| 113 | 115 | var z: u32 = undefined; |
| 114 | 116 | var x: u8, const y, z = .{ 1, 2, 3 }; |
| 117 | _ = &x; | |
| 115 | 118 | |
| 116 | 119 | comptime assert(@TypeOf(y) == comptime_int); |
| 117 | 120 | comptime assert(y == 2); |
| ... | ... | @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn |
| 122 | 125 | |
| 123 | 126 | test "destructure of tuple with comptime fields results in some comptime-known values" { |
| 124 | 127 | var runtime: u32 = 42; |
| 128 | _ = &runtime; | |
| 125 | 129 | const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; |
| 126 | 130 | |
| 127 | 131 | // a, c are comptime-known |
test/behavior/empty_union.zig+4| ... | ... | @@ -5,12 +5,14 @@ const expect = std.testing.expect; |
| 5 | 5 | test "switch on empty enum" { |
| 6 | 6 | const E = enum {}; |
| 7 | 7 | var e: E = undefined; |
| 8 | _ = &e; | |
| 8 | 9 | switch (e) {} |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | 12 | test "switch on empty enum with a specified tag type" { |
| 12 | 13 | const E = enum(u8) {}; |
| 13 | 14 | var e: E = undefined; |
| 15 | _ = &e; | |
| 14 | 16 | switch (e) {} |
| 15 | 17 | } |
| 16 | 18 | |
| ... | ... | @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { |
| 19 | 21 | |
| 20 | 22 | const U = union(enum(u8)) {}; |
| 21 | 23 | var u: U = undefined; |
| 24 | _ = &u; | |
| 22 | 25 | switch (u) {} |
| 23 | 26 | } |
| 24 | 27 | |
| ... | ... | @@ -28,6 +31,7 @@ test "switch on empty tagged union" { |
| 28 | 31 | const E = enum {}; |
| 29 | 32 | const U = union(E) {}; |
| 30 | 33 | var u: U = undefined; |
| 34 | _ = &u; | |
| 31 | 35 | switch (u) {} |
| 32 | 36 | } |
| 33 | 37 |
test/behavior/enum.zig+11-4| ... | ... | @@ -579,6 +579,7 @@ test "enum literal cast to enum" { |
| 579 | 579 | |
| 580 | 580 | var color1: Color = .Auto; |
| 581 | 581 | var color2 = Color.Auto; |
| 582 | _ = .{ &color1, &color2 }; | |
| 582 | 583 | try expect(color1 == color2); |
| 583 | 584 | } |
| 584 | 585 | |
| ... | ... | @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { |
| 663 | 664 | const E = enum(u8) { _ }; |
| 664 | 665 | |
| 665 | 666 | fn doTheTest(y: u8) !void { |
| 666 | var e = @as(E, @enumFromInt(y)); | |
| 667 | var e: E = @enumFromInt(y); | |
| 668 | _ = &e; | |
| 667 | 669 | try expect(switch (e) { |
| 668 | 670 | _ => true, |
| 669 | 671 | }); |
| ... | ... | @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { |
| 858 | 860 | const State = enum { Start }; |
| 859 | 861 | test "switch on enum with one member is comptime-known" { |
| 860 | 862 | var state = State.Start; |
| 863 | _ = &state; | |
| 861 | 864 | switch (state) { |
| 862 | 865 | State.Start => return, |
| 863 | 866 | } |
| ... | ... | @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { |
| 917 | 920 | |
| 918 | 921 | var t = true; |
| 919 | 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 | 925 | switch (y) { |
| 922 | 926 | .x86_64 => {}, |
| 923 | 927 | else => @panic("fail"), |
| ... | ... | @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { |
| 1031 | 1035 | B = 0, |
| 1032 | 1036 | }; |
| 1033 | 1037 | var b = LocalFoo.B; |
| 1038 | _ = &b; | |
| 1034 | 1039 | try expect(mem.eql(u8, @tagName(b), "B")); |
| 1035 | 1040 | } |
| 1036 | 1041 | |
| ... | ... | @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { |
| 1055 | 1060 | delta = 65, |
| 1056 | 1061 | }; |
| 1057 | 1062 | var b = LocalFoo.bravo; |
| 1063 | _ = &b; | |
| 1058 | 1064 | try expect(mem.eql(u8, @tagName(b), "bravo")); |
| 1059 | 1065 | } |
| 1060 | 1066 | |
| ... | ... | @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { |
| 1135 | 1141 | const E = enum { a, b }; |
| 1136 | 1142 | var b = E.a; |
| 1137 | 1143 | var a = @tagName(b); |
| 1138 | _ = a; | |
| 1144 | _ = .{ &a, &b }; | |
| 1139 | 1145 | } |
| 1140 | 1146 | { |
| 1141 | 1147 | const E = enum { a, b, c, d, e, f }; |
| 1142 | 1148 | var b = E.a; |
| 1143 | 1149 | var a = @tagName(b); |
| 1144 | _ = a; | |
| 1150 | _ = .{ &a, &b }; | |
| 1145 | 1151 | } |
| 1146 | 1152 | } |
| 1147 | 1153 | |
| ... | ... | @@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { |
| 1189 | 1195 | test "runtime int to enum with one possible value" { |
| 1190 | 1196 | const E = enum { one }; |
| 1191 | 1197 | var runtime: usize = 0; |
| 1198 | _ = &runtime; | |
| 1192 | 1199 | if (@as(E, @enumFromInt(runtime)) != .one) { |
| 1193 | 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 | 102 | |
| 103 | 103 | const S = struct { |
| 104 | 104 | fn errorable() !u64 { |
| 105 | var x = @as(u64, try number()); | |
| 106 | return x; | |
| 105 | return @as(u64, try number()); | |
| 107 | 106 | } |
| 108 | 107 | |
| 109 | 108 | fn number() anyerror!u32 { |
| ... | ... | @@ -119,7 +118,7 @@ test "debug info for optional error set" { |
| 119 | 118 | |
| 120 | 119 | const SomeError = error{ Hello, Hello2 }; |
| 121 | 120 | var a_local_variable: ?SomeError = null; |
| 122 | _ = a_local_variable; | |
| 121 | _ = &a_local_variable; | |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | 124 | test "implicit cast to optional to error union to return result loc" { |
| ... | ... | @@ -160,6 +159,7 @@ fn entry() void { |
| 160 | 159 | |
| 161 | 160 | fn entryPtr() void { |
| 162 | 161 | var ptr = &bar2; |
| 162 | _ = &ptr; | |
| 163 | 163 | fooPtr(ptr); |
| 164 | 164 | } |
| 165 | 165 | |
| ... | ... | @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; |
| 226 | 226 | const Set2 = error{ A, C }; |
| 227 | 227 | |
| 228 | 228 | fn testExplicitErrorSetCast(set1: Set1) !void { |
| 229 | var x = @as(Set2, @errorCast(set1)); | |
| 229 | const x: Set2 = @errorCast(set1); | |
| 230 | 230 | try expect(@TypeOf(x) == Set2); |
| 231 | var y = @as(Set1, @errorCast(x)); | |
| 231 | const y: Set1 = @errorCast(x); | |
| 232 | 232 | try expect(@TypeOf(y) == Set1); |
| 233 | 233 | try expect(y == error.A); |
| 234 | 234 | } |
| ... | ... | @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { |
| 408 | 408 | }; |
| 409 | 409 | |
| 410 | 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 | 412 | return x.a; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 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 | 417 | return x.a; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 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 | 422 | return x.a; |
| 423 | 423 | } |
| 424 | 424 | |
| ... | ... | @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { |
| 673 | 673 | const a: error{B}!void = {}; |
| 674 | 674 | const b: error{A}!void = {}; |
| 675 | 675 | var cond = true; |
| 676 | _ = &cond; | |
| 676 | 677 | const err = if (cond) a else b; |
| 677 | 678 | try err; |
| 678 | 679 | } |
| ... | ... | @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { |
| 681 | 682 | const S = struct { |
| 682 | 683 | fn foo() !void { |
| 683 | 684 | var a = false; |
| 685 | _ = &a; | |
| 684 | 686 | if (a) { |
| 685 | 687 | const b: error{A}!void = error.A; |
| 686 | 688 | return b; |
| ... | ... | @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { |
| 831 | 833 | |
| 832 | 834 | fn foo() anyerror!I { |
| 833 | 835 | var i: I = .{ .x = 1234 }; |
| 836 | _ = &i; | |
| 834 | 837 | return i; |
| 835 | 838 | } |
| 836 | 839 | }; |
| ... | ... | @@ -842,6 +845,7 @@ test "compare error union and error set" { |
| 842 | 845 | |
| 843 | 846 | var a: anyerror = error.Foo; |
| 844 | 847 | var b: anyerror!u32 = error.Bar; |
| 848 | _ = &a; | |
| 845 | 849 | |
| 846 | 850 | try expect(a != b); |
| 847 | 851 | try expect(b != a); |
| ... | ... | @@ -863,6 +867,7 @@ fn non_errorable() void { |
| 863 | 867 | // This test is needed because stage 2's fix for #1923 means that catch blocks interact |
| 864 | 868 | // with the error return trace index. |
| 865 | 869 | var x: error{Foo}!void = {}; |
| 870 | _ = &x; | |
| 866 | 871 | return x catch {}; |
| 867 | 872 | } |
| 868 | 873 | |
| ... | ... | @@ -902,6 +907,7 @@ test "optional error union return type" { |
| 902 | 907 | const S = struct { |
| 903 | 908 | fn foo() ?anyerror!u32 { |
| 904 | 909 | var x: u32 = 1234; |
| 910 | _ = &x; | |
| 905 | 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 | 37 | const x: i32 = 1; |
| 38 | 38 | const y: i32 = 2; |
| 39 | 39 | comptime var z: i32 = if (a) x else y; |
| 40 | _ = &z; | |
| 40 | 41 | return z; |
| 41 | 42 | } |
| 42 | 43 | test "inline variable gets result of const if" { |
| ... | ... | @@ -74,6 +75,7 @@ test "constant expressions" { |
| 74 | 75 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 75 | 76 | |
| 76 | 77 | var array: [array_size]u8 = undefined; |
| 78 | _ = &array; | |
| 77 | 79 | try expect(@sizeOf(@TypeOf(array)) == 20); |
| 78 | 80 | } |
| 79 | 81 | const array_size: u8 = 20; |
| ... | ... | @@ -129,7 +131,7 @@ test "pointer to type" { |
| 129 | 131 | comptime { |
| 130 | 132 | var T: type = i32; |
| 131 | 133 | try expect(T == i32); |
| 132 | var ptr = &T; | |
| 134 | const ptr = &T; | |
| 133 | 135 | try expect(@TypeOf(ptr) == *type); |
| 134 | 136 | ptr.* = f32; |
| 135 | 137 | try expect(T == f32); |
| ... | ... | @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { |
| 372 | 374 | test "zero extend from u0 to u1" { |
| 373 | 375 | var zero_u0: u0 = 0; |
| 374 | 376 | var zero_u1: u1 = zero_u0; |
| 377 | _ = .{ &zero_u0, &zero_u1 }; | |
| 375 | 378 | try expect(zero_u1 == 0); |
| 376 | 379 | } |
| 377 | 380 | |
| ... | ... | @@ -408,6 +411,7 @@ test "inline for with same type but different values" { |
| 408 | 411 | var res: usize = 0; |
| 409 | 412 | inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { |
| 410 | 413 | var a: T = undefined; |
| 414 | _ = &a; | |
| 411 | 415 | res += a.len; |
| 412 | 416 | } |
| 413 | 417 | try expect(res == 5); |
| ... | ... | @@ -460,9 +464,9 @@ test "comptime shl" { |
| 460 | 464 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 461 | 465 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 462 | 466 | |
| 463 | var a: u128 = 3; | |
| 464 | var b: u7 = 63; | |
| 465 | var c: u128 = 3 << 63; | |
| 467 | const a: u128 = 3; | |
| 468 | const b: u7 = 63; | |
| 469 | const c: u128 = 3 << 63; | |
| 466 | 470 | try expect((a << b) == c); |
| 467 | 471 | } |
| 468 | 472 | |
| ... | ... | @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { |
| 489 | 493 | |
| 490 | 494 | const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; |
| 491 | 495 | var a = ~@as(u64, 0); |
| 496 | _ = &a; | |
| 492 | 497 | const rt_shifted = @shlWithOverflow(a, 16)[0]; |
| 493 | 498 | |
| 494 | 499 | try expect(ct_shifted == rt_shifted); |
| ... | ... | @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { |
| 521 | 526 | |
| 522 | 527 | var a: u128 = 152313999999999991610955792383; |
| 523 | 528 | var b: u128 = 10000000000000000000; |
| 524 | var c = a / b; | |
| 529 | _ = .{ &a, &b }; | |
| 530 | const c = a / b; | |
| 525 | 531 | try expect(c == 15231399999); |
| 526 | 532 | } |
| 527 | 533 | |
| ... | ... | @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio |
| 555 | 561 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 556 | 562 | |
| 557 | 563 | var runtime = [1]i32{3}; |
| 564 | _ = &runtime; | |
| 558 | 565 | comptime var i: usize = 0; |
| 559 | 566 | inline while (i < 2) : (i += 1) { |
| 560 | 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 | 699 | }; |
| 693 | 700 | |
| 694 | 701 | const s = S{ .a = 2 }; |
| 695 | var b = s.b(); | |
| 702 | const b = s.b(); | |
| 696 | 703 | try expect(b == 2); |
| 697 | 704 | } |
| 698 | 705 | |
| ... | ... | @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { |
| 759 | 766 | |
| 760 | 767 | var a = [2]u3{ 1, 7 }; |
| 761 | 768 | var b = [3]u8{ 200, 225, 255 }; |
| 762 | var c = a ++ b; | |
| 769 | _ = .{ &a, &b }; | |
| 770 | const c = a ++ b; | |
| 763 | 771 | comptime assert(@TypeOf(c) == [5]u8); |
| 764 | 772 | try expect(c[0] == 1); |
| 765 | 773 | try expect(c[1] == 7); |
| ... | ... | @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { |
| 775 | 783 | |
| 776 | 784 | var a = [2]u3{ 1, 7 }; |
| 777 | 785 | var b = [3]u8{ 200, 225, 255 }; |
| 778 | var c = &a ++ &b; | |
| 786 | const c = &a ++ &b; | |
| 779 | 787 | comptime assert(@TypeOf(c) == *[5]u8); |
| 780 | 788 | try expect(c[0] == 1); |
| 781 | 789 | try expect(c[1] == 7); |
| ... | ... | @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { |
| 791 | 799 | |
| 792 | 800 | var a = [2]u3{ 1, 7 }; |
| 793 | 801 | var b = [3:69]u8{ 200, 225, 255 }; |
| 794 | var c = a ++ b; | |
| 802 | _ = .{ &a, &b }; | |
| 803 | const c = a ++ b; | |
| 795 | 804 | comptime assert(@TypeOf(c) == [5:69]u8); |
| 796 | 805 | try expect(c[0] == 1); |
| 797 | 806 | try expect(c[1] == 7); |
| 798 | 807 | try expect(c[2] == 200); |
| 799 | 808 | try expect(c[3] == 225); |
| 800 | 809 | try expect(c[4] == 255); |
| 801 | var ptr: [*]const u8 = &c; | |
| 810 | const ptr: [*]const u8 = &c; | |
| 802 | 811 | try expect(ptr[5] == 69); |
| 803 | 812 | } |
| 804 | 813 | |
| ... | ... | @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { |
| 808 | 817 | |
| 809 | 818 | var a = [2]u3{ 1, 7 }; |
| 810 | 819 | var b = [3:69]u8{ 200, 225, 255 }; |
| 811 | var c = &a ++ &b; | |
| 820 | const c = &a ++ &b; | |
| 812 | 821 | comptime assert(@TypeOf(c) == *[5:69]u8); |
| 813 | 822 | try expect(c[0] == 1); |
| 814 | 823 | try expect(c[1] == 7); |
| 815 | 824 | try expect(c[2] == 200); |
| 816 | 825 | try expect(c[3] == 225); |
| 817 | 826 | try expect(c[4] == 255); |
| 818 | var ptr: [*]const u8 = c; | |
| 827 | const ptr: [*]const u8 = c; | |
| 819 | 828 | try expect(ptr[5] == 69); |
| 820 | 829 | } |
| 821 | 830 | |
| ... | ... | @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { |
| 825 | 834 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 826 | 835 | |
| 827 | 836 | var a = [2:7]u3{ 1, 6 }; |
| 828 | var b = a ** 2; | |
| 837 | _ = &a; | |
| 838 | const b = a ** 2; | |
| 829 | 839 | comptime assert(@TypeOf(b) == [4:7]u3); |
| 830 | 840 | try expect(b[0] == 1); |
| 831 | 841 | try expect(b[1] == 6); |
| 832 | 842 | try expect(b[2] == 1); |
| 833 | 843 | try expect(b[3] == 6); |
| 834 | var ptr: [*]const u3 = &b; | |
| 844 | const ptr: [*]const u3 = &b; | |
| 835 | 845 | try expect(ptr[4] == 7); |
| 836 | 846 | } |
| 837 | 847 | |
| ... | ... | @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { |
| 841 | 851 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 842 | 852 | |
| 843 | 853 | var a = [2:7]u3{ 1, 6 }; |
| 844 | var b = &a ** 2; | |
| 854 | const b = &a ** 2; | |
| 845 | 855 | comptime assert(@TypeOf(b) == *[4:7]u3); |
| 846 | 856 | try expect(b[0] == 1); |
| 847 | 857 | try expect(b[1] == 6); |
| 848 | 858 | try expect(b[2] == 1); |
| 849 | 859 | try expect(b[3] == 6); |
| 850 | var ptr: [*]const u3 = b; | |
| 860 | const ptr: [*]const u3 = b; | |
| 851 | 861 | try expect(ptr[4] == 7); |
| 852 | 862 | } |
| 853 | 863 | |
| ... | ... | @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { |
| 913 | 923 | .x = i, |
| 914 | 924 | }; |
| 915 | 925 | } |
| 916 | var ptr = @as([*]S, @ptrCast(&array)); | |
| 917 | var x = ptr[0].x; | |
| 926 | var ptr: [*]S = @ptrCast(&array); | |
| 927 | const x = ptr[0].x; | |
| 918 | 928 | assert(x == 0); |
| 919 | 929 | ptr += 1; |
| 920 | 930 | assert(ptr[1].x == 2); |
| ... | ... | @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { |
| 953 | 963 | const S = struct { |
| 954 | 964 | fn b(c: anytype) !void { |
| 955 | 965 | const D = struct { c: @TypeOf(c) }; |
| 956 | var d = D{ .c = c }; | |
| 966 | const d: D = .{ .c = c }; | |
| 957 | 967 | try expect(d.c == 1234); |
| 958 | 968 | } |
| 959 | 969 | }; |
| 960 | 970 | var c: i32 = 1234; |
| 971 | _ = &c; | |
| 961 | 972 | try S.b(c); |
| 962 | 973 | } |
| 963 | 974 | |
| ... | ... | @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { |
| 966 | 977 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 967 | 978 | |
| 968 | 979 | var x: u32 = 1234; |
| 980 | _ = &x; | |
| 969 | 981 | const S = struct { val: @TypeOf(x + 100) }; |
| 970 | 982 | const s: S = .{ .val = x }; |
| 971 | 983 | try expect(s.val == 1234); |
| ... | ... | @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea |
| 977 | 989 | const S = struct { |
| 978 | 990 | fn doTheTest() !void { |
| 979 | 991 | var runtime: u8 = 'b'; |
| 992 | _ = &runtime; | |
| 980 | 993 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { |
| 981 | 994 | bar(); |
| 982 | 995 | if (byte == runtime) { |
| ... | ... | @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t |
| 1010 | 1023 | const S = struct { |
| 1011 | 1024 | fn doTheTest() !void { |
| 1012 | 1025 | var runtime: u8 = 'b'; |
| 1026 | _ = &runtime; | |
| 1013 | 1027 | outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { |
| 1014 | 1028 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { |
| 1015 | 1029 | bar(outer_byte); |
| ... | ... | @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { |
| 1387 | 1401 | |
| 1388 | 1402 | test "inline for inside a runtime condition" { |
| 1389 | 1403 | var a = false; |
| 1404 | _ = &a; | |
| 1390 | 1405 | if (a) { |
| 1391 | 1406 | const arr = .{ 1, 2, 3 }; |
| 1392 | 1407 | inline for (arr) |val| { |
| ... | ... | @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { |
| 1522 | 1537 | |
| 1523 | 1538 | const array = [1]u8{'A'} ++ [1]?u8{null}; |
| 1524 | 1539 | var index: usize = 0; |
| 1540 | _ = &index; | |
| 1525 | 1541 | try expect(array[index].? == 'A'); |
| 1526 | 1542 | } |
| 1527 | 1543 | |
| ... | ... | @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { |
| 1556 | 1572 | var v: @This() = c; |
| 1557 | 1573 | }; |
| 1558 | 1574 | var p = &S.c; |
| 1575 | _ = &p; | |
| 1559 | 1576 | try std.testing.expect(p.x == S.c.x); |
| 1560 | 1577 | S.v.x = 2; |
| 1561 | 1578 | try std.testing.expect(p.x == S.c.x); |
| ... | ... | @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { |
| 1625 | 1642 | test "if inside a switch" { |
| 1626 | 1643 | var condition = true; |
| 1627 | 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 | 1647 | 0 => if (condition) 2 else 3, |
| 1630 | 1648 | 1 => 100, |
| 1631 | 1649 | 2 => 200, |
| ... | ... | @@ -1673,6 +1691,7 @@ test "@inComptime" { |
| 1673 | 1691 | comptime { |
| 1674 | 1692 | var foo = [3]u8{ 0x55, 0x55, 0x55 }; |
| 1675 | 1693 | var bar = [2]u8{ 1, 2 }; |
| 1694 | _ = .{ &foo, &bar }; | |
| 1676 | 1695 | foo[0..2].* = bar; |
| 1677 | 1696 | assert(foo[0] == 1); |
| 1678 | 1697 | assert(foo[1] == 2); |
test/behavior/extern_struct_zero_size_fields.zig+1-1| ... | ... | @@ -17,5 +17,5 @@ const T = extern struct { |
| 17 | 17 | |
| 18 | 18 | test { |
| 19 | 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 | 42 | fn testAdd(comptime T: type) !void { |
| 43 | 43 | var one_point_two_five: T = 1.25; |
| 44 | 44 | var two_point_seven_five: T = 2.75; |
| 45 | _ = &one_point_two_five; | |
| 46 | _ = &two_point_seven_five; | |
| 45 | 47 | try expect(one_point_two_five + two_point_seven_five == 4); |
| 46 | 48 | } |
| 47 | 49 | |
| ... | ... | @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { |
| 74 | 76 | fn testSub(comptime T: type) !void { |
| 75 | 77 | var one_point_two_five: T = 1.25; |
| 76 | 78 | var two_point_seven_five: T = 2.75; |
| 79 | _ = &one_point_two_five; | |
| 80 | _ = &two_point_seven_five; | |
| 77 | 81 | try expect(one_point_two_five - two_point_seven_five == -1.5); |
| 78 | 82 | } |
| 79 | 83 | |
| ... | ... | @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { |
| 106 | 110 | fn testMul(comptime T: type) !void { |
| 107 | 111 | var one_point_two_five: T = 1.25; |
| 108 | 112 | var two_point_seven_five: T = 2.75; |
| 113 | _ = &one_point_two_five; | |
| 114 | _ = &two_point_seven_five; | |
| 109 | 115 | try expect(one_point_two_five * two_point_seven_five == 3.4375); |
| 110 | 116 | } |
| 111 | 117 | |
| ... | ... | @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { |
| 152 | 158 | { |
| 153 | 159 | // No decimal part |
| 154 | 160 | var x: T = 1.0; |
| 161 | _ = &x; | |
| 155 | 162 | try expect(x == 1.0); |
| 156 | 163 | try expect(x != 0.0); |
| 157 | 164 | try expect(x > 0.0); |
| ... | ... | @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { |
| 162 | 169 | { |
| 163 | 170 | // Non-zero decimal part |
| 164 | 171 | var x: T = 1.5; |
| 172 | _ = &x; | |
| 165 | 173 | try expect(x != 1.0); |
| 166 | 174 | try expect(x != 2.0); |
| 167 | 175 | try expect(x > 1.0); |
| ... | ... | @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { |
| 184 | 192 | math.floatMax(T), |
| 185 | 193 | math.inf(T), |
| 186 | 194 | }; |
| 195 | _ = &edges; | |
| 187 | 196 | for (edges, 0..) |rhs, rhs_i| { |
| 188 | 197 | for (edges, 0..) |lhs, lhs_i| { |
| 189 | 198 | const no_nan = lhs_i != 5 and rhs_i != 5; |
| ... | ... | @@ -212,6 +221,7 @@ test "different sized float comparisons" { |
| 212 | 221 | fn testDifferentSizedFloatComparisons() !void { |
| 213 | 222 | var a: f16 = 1; |
| 214 | 223 | var b: f64 = 2; |
| 224 | _ = .{ &a, &b }; | |
| 215 | 225 | try expect(a < b); |
| 216 | 226 | } |
| 217 | 227 | |
| ... | ... | @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { |
| 240 | 250 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 241 | 251 | |
| 242 | 252 | const a: f128 = -2; |
| 243 | var b = @as(i64, @intFromFloat(a)); | |
| 253 | var b: i64 = @intFromFloat(a); | |
| 254 | _ = &b; | |
| 244 | 255 | try expect(@as(i64, -2) == b); |
| 245 | 256 | } |
| 246 | 257 | |
| ... | ... | @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { |
| 331 | 342 | try expect(math.isNan(@sqrt(neg_one))); |
| 332 | 343 | var nan: T = math.nan(T); |
| 333 | 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 | } |
| 335 | 368 | |
| 336 | 369 | test "@sqrt with vectors" { |
| ... | ... | @@ -345,7 +378,8 @@ test "@sqrt with vectors" { |
| 345 | 378 | |
| 346 | 379 | fn testSqrtWithVectors() !void { |
| 347 | 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 | 383 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); |
| 350 | 384 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); |
| 351 | 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 | 428 | fn testSin(comptime T: type) !void { |
| 395 | 429 | const eps = epsForType(T); |
| 396 | 430 | var zero: T = 0; |
| 431 | _ = &zero; | |
| 397 | 432 | try expect(@sin(zero) == 0); |
| 398 | 433 | var pi: T = math.pi; |
| 434 | _ = &pi; | |
| 399 | 435 | try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); |
| 400 | 436 | try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); |
| 401 | 437 | try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); |
| ... | ... | @@ -414,7 +450,8 @@ test "@sin with vectors" { |
| 414 | 450 | |
| 415 | 451 | fn testSinWithVectors() !void { |
| 416 | 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 | 455 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); |
| 419 | 456 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); |
| 420 | 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 | 500 | fn testCos(comptime T: type) !void { |
| 464 | 501 | const eps = epsForType(T); |
| 465 | 502 | var zero: T = 0; |
| 503 | _ = &zero; | |
| 466 | 504 | try expect(@cos(zero) == 1); |
| 467 | 505 | var pi: T = math.pi; |
| 506 | _ = &pi; | |
| 468 | 507 | try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); |
| 469 | 508 | try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); |
| 470 | 509 | try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); |
| ... | ... | @@ -483,7 +522,8 @@ test "@cos with vectors" { |
| 483 | 522 | |
| 484 | 523 | fn testCosWithVectors() !void { |
| 485 | 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 | 527 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); |
| 488 | 528 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); |
| 489 | 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 | 572 | fn testTan(comptime T: type) !void { |
| 533 | 573 | const eps = epsForType(T); |
| 534 | 574 | var zero: T = 0; |
| 575 | _ = &zero; | |
| 535 | 576 | try expect(@tan(zero) == 0); |
| 536 | 577 | var pi: T = math.pi; |
| 578 | _ = &pi; | |
| 537 | 579 | try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); |
| 538 | 580 | try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); |
| 539 | 581 | try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); |
| ... | ... | @@ -552,7 +594,8 @@ test "@tan with vectors" { |
| 552 | 594 | |
| 553 | 595 | fn testTanWithVectors() !void { |
| 554 | 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 | 599 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); |
| 557 | 600 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); |
| 558 | 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 | 643 | |
| 601 | 644 | fn testExp(comptime T: type) !void { |
| 602 | 645 | const eps = epsForType(T); |
| 646 | ||
| 603 | 647 | var zero: T = 0; |
| 648 | _ = &zero; | |
| 604 | 649 | try expect(@exp(zero) == 1); |
| 650 | ||
| 605 | 651 | var two: T = 2; |
| 652 | _ = &two; | |
| 606 | 653 | try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); |
| 654 | ||
| 607 | 655 | var five: T = 5; |
| 656 | _ = &five; | |
| 608 | 657 | try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); |
| 609 | 658 | } |
| 610 | 659 | |
| ... | ... | @@ -621,7 +670,8 @@ test "@exp with vectors" { |
| 621 | 670 | |
| 622 | 671 | fn testExpWithVectors() !void { |
| 623 | 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 | 675 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); |
| 626 | 676 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); |
| 627 | 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 | 725 | try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); |
| 676 | 726 | var four_point_five: T = 4.5; |
| 677 | 727 | try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); |
| 728 | _ = .{ &two, &one_point_five, &four_point_five }; | |
| 678 | 729 | } |
| 679 | 730 | |
| 680 | 731 | test "@exp2 with @vectors" { |
| ... | ... | @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { |
| 690 | 741 | |
| 691 | 742 | fn testExp2WithVectors() !void { |
| 692 | 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 | 746 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); |
| 695 | 747 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); |
| 696 | 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 | 796 | try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); |
| 745 | 797 | var five: T = 5; |
| 746 | 798 | try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); |
| 799 | _ = .{ &e, &two, &five }; | |
| 747 | 800 | } |
| 748 | 801 | |
| 749 | 802 | test "@log with @vectors" { |
| ... | ... | @@ -756,7 +809,8 @@ test "@log with @vectors" { |
| 756 | 809 | |
| 757 | 810 | { |
| 758 | 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 | 814 | try expect(@log(@as(f32, 1.1)) == result[0]); |
| 761 | 815 | try expect(@log(@as(f32, 2.2)) == result[1]); |
| 762 | 816 | try expect(@log(@as(f32, 0.3)) == result[2]); |
| ... | ... | @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { |
| 811 | 865 | try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); |
| 812 | 866 | var ten: T = 10; |
| 813 | 867 | try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); |
| 868 | _ = .{ &four, &six, &ten }; | |
| 814 | 869 | } |
| 815 | 870 | |
| 816 | 871 | test "@log2 with vectors" { |
| ... | ... | @@ -830,7 +885,8 @@ test "@log2 with vectors" { |
| 830 | 885 | |
| 831 | 886 | fn testLog2WithVectors() !void { |
| 832 | 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 | 890 | try expect(@log2(@as(f32, 1.1)) == result[0]); |
| 835 | 891 | try expect(@log2(@as(f32, 2.2)) == result[1]); |
| 836 | 892 | try expect(@log2(@as(f32, 0.3)) == result[2]); |
| ... | ... | @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { |
| 884 | 940 | try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); |
| 885 | 941 | var fifty: T = 50; |
| 886 | 942 | try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); |
| 943 | _ = .{ &hundred, &fifteen, &fifty }; | |
| 887 | 944 | } |
| 888 | 945 | |
| 889 | 946 | test "@log10 with vectors" { |
| ... | ... | @@ -899,7 +956,8 @@ test "@log10 with vectors" { |
| 899 | 956 | |
| 900 | 957 | fn testLog10WithVectors() !void { |
| 901 | 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 | 961 | try expect(@log10(@as(f32, 1.1)) == result[0]); |
| 904 | 962 | try expect(@log10(@as(f32, 2.2)) == result[1]); |
| 905 | 963 | try expect(@log10(@as(f32, 0.3)) == result[2]); |
| ... | ... | @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { |
| 987 | 1045 | try expect(math.isPositiveInf(@abs(neg_inf))); |
| 988 | 1046 | var nan: T = math.nan(T); |
| 989 | 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 | } |
| 991 | 1069 | |
| 992 | 1070 | test "@abs with vectors" { |
| ... | ... | @@ -1001,7 +1079,8 @@ test "@abs with vectors" { |
| 1001 | 1079 | |
| 1002 | 1080 | fn testFabsWithVectors() !void { |
| 1003 | 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 | 1084 | try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); |
| 1006 | 1085 | try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); |
| 1007 | 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 | 1149 | try expect(@floor(fourteen_point_seven) == 14.0); |
| 1071 | 1150 | var neg_fourteen_point_seven: T = -14.7; |
| 1072 | 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 | } |
| 1074 | 1164 | |
| 1075 | 1165 | test "@floor with vectors" { |
| ... | ... | @@ -1086,7 +1176,8 @@ test "@floor with vectors" { |
| 1086 | 1176 | |
| 1087 | 1177 | fn testFloorWithVectors() !void { |
| 1088 | 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 | 1181 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); |
| 1091 | 1182 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); |
| 1092 | 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 | 1246 | try expect(@ceil(fourteen_point_seven) == 15.0); |
| 1156 | 1247 | var neg_fourteen_point_seven: T = -14.7; |
| 1157 | 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 | } |
| 1159 | 1261 | |
| 1160 | 1262 | test "@ceil with vectors" { |
| ... | ... | @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { |
| 1171 | 1273 | |
| 1172 | 1274 | fn testCeilWithVectors() !void { |
| 1173 | 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 | 1278 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); |
| 1176 | 1279 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); |
| 1177 | 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 | 1353 | try expect(@trunc(fourteen_point_seven) == 14.0); |
| 1251 | 1354 | var neg_fourteen_point_seven: T = -14.7; |
| 1252 | 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 | } |
| 1254 | 1368 | |
| 1255 | 1369 | test "@trunc with vectors" { |
| ... | ... | @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { |
| 1266 | 1380 | |
| 1267 | 1381 | fn testTruncWithVectors() !void { |
| 1268 | 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 | 1385 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); |
| 1271 | 1386 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); |
| 1272 | 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 | 1480 | var neg_nan: T = -math.nan(T); |
| 1366 | 1481 | try expect(math.isNan(-neg_nan)); |
| 1367 | 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 | } |
| 1369 | 1505 | |
| 1370 | 1506 | test "eval @setFloatMode at compile-time" { |
test/behavior/fn.zig+9-4| ... | ... | @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { |
| 21 | 21 | |
| 22 | 22 | test "mutable local variables" { |
| 23 | 23 | var zero: i32 = 0; |
| 24 | _ = &zero; | |
| 24 | 25 | try expect(zero == 0); |
| 25 | 26 | |
| 26 | 27 | var i = @as(i32, 0); |
| ... | ... | @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { |
| 70 | 71 | test "return inner function which references comptime variable of outer function" { |
| 71 | 72 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 72 | 73 | |
| 73 | var func = outer(10); | |
| 74 | const func = outer(10); | |
| 74 | 75 | try expect(func(3) == 7); |
| 75 | 76 | } |
| 76 | 77 | |
| ... | ... | @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { |
| 259 | 260 | |
| 260 | 261 | const S = struct { |
| 261 | 262 | fn entry() !void { |
| 262 | var x = Foo{ | |
| 263 | const x = Foo{ | |
| 263 | 264 | .field = optionalPtr(), |
| 264 | 265 | }; |
| 265 | 266 | try expect(x.field.?.* == 999); |
| ... | ... | @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { |
| 386 | 387 | const S = struct { |
| 387 | 388 | fn doTheTest() !void { |
| 388 | 389 | var x: i32 = 1; |
| 390 | _ = &x; | |
| 389 | 391 | try expect(foo(x) == 10); |
| 390 | 392 | try expect(foo(i32) == 20); |
| 391 | 393 | } |
| ... | ... | @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { |
| 413 | 415 | |
| 414 | 416 | const S = struct { |
| 415 | 417 | fn get() @import("std").ArrayListUnmanaged(i32) { |
| 416 | var x: @import("std").ArrayListUnmanaged(i32) = .{}; | |
| 418 | const x: @import("std").ArrayListUnmanaged(i32) = .{}; | |
| 417 | 419 | return x; |
| 418 | 420 | } |
| 419 | 421 | }; |
| 420 | var list = S.get(); | |
| 422 | const list = S.get(); | |
| 421 | 423 | try expect(list.items.len == 0); |
| 422 | 424 | } |
| 423 | 425 | |
| ... | ... | @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { |
| 434 | 436 | } |
| 435 | 437 | }; |
| 436 | 438 | var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; |
| 439 | _ = &fnPtr1; | |
| 437 | 440 | try expect(fnPtr1() == 123); |
| 438 | 441 | const S2 = struct { |
| 439 | 442 | extern fn someFunctionThatReturnsAValue() c_int; |
| 440 | 443 | }; |
| 441 | 444 | var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; |
| 445 | _ = &fnPtr2; | |
| 442 | 446 | try expect(fnPtr2() == 123); |
| 443 | 447 | } |
| 444 | 448 | |
| ... | ... | @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { |
| 588 | 592 | const bar = foo; |
| 589 | 593 | }; |
| 590 | 594 | var a = &S.bar; |
| 595 | _ = &a; | |
| 591 | 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 | 5 | comptime { |
| 6 | 6 | return struct { |
| 7 | 7 | fn func(ptr: *u8) usize { |
| 8 | var u = @intFromPtr(ptr); | |
| 9 | return u; | |
| 8 | return @intFromPtr(ptr); | |
| 10 | 9 | } |
| 11 | 10 | }.func; |
| 12 | 11 | } |
test/behavior/for.zig+13-6| ... | ... | @@ -26,7 +26,7 @@ test "break from outer for loop" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | fn testBreakOuter() !void { |
| 29 | var array = "aoeu"; | |
| 29 | const array = "aoeu"; | |
| 30 | 30 | var count: usize = 0; |
| 31 | 31 | outer: for (array) |_| { |
| 32 | 32 | for (array) |_| { |
| ... | ... | @@ -43,7 +43,7 @@ test "continue outer for loop" { |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | fn testContinueOuter() !void { |
| 46 | var array = "aoeu"; | |
| 46 | const array = "aoeu"; | |
| 47 | 47 | var counter: usize = 0; |
| 48 | 48 | outer: for (array) |_| { |
| 49 | 49 | for (array) |_| { |
| ... | ... | @@ -137,7 +137,7 @@ test "2 break statements and an else" { |
| 137 | 137 | fn entry(t: bool, f: bool) !void { |
| 138 | 138 | var buf: [10]u8 = undefined; |
| 139 | 139 | var ok = false; |
| 140 | ok = for (buf) |item| { | |
| 140 | ok = for (&buf) |*item| { | |
| 141 | 141 | _ = item; |
| 142 | 142 | if (f) break false; |
| 143 | 143 | if (t) break true; |
| ... | ... | @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { |
| 201 | 201 | |
| 202 | 202 | const S = struct { |
| 203 | 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 | 205 | for (ptr, 0..) |x, i| try expect(x == i + 1); |
| 206 | 206 | for (ptr, 0..) |*x, i| try expect(x.* == i + 1); |
| 207 | 207 | } |
| ... | ... | @@ -230,6 +230,7 @@ test "for loop with else branch" { |
| 230 | 230 | |
| 231 | 231 | { |
| 232 | 232 | var x = [_]u32{ 1, 2 }; |
| 233 | _ = &x; | |
| 233 | 234 | const q = for (x) |y| { |
| 234 | 235 | if ((y & 1) != 0) continue; |
| 235 | 236 | break y * 2; |
| ... | ... | @@ -238,6 +239,7 @@ test "for loop with else branch" { |
| 238 | 239 | } |
| 239 | 240 | { |
| 240 | 241 | var x = [_]u32{ 1, 2 }; |
| 242 | _ = &x; | |
| 241 | 243 | const q = for (x) |y| { |
| 242 | 244 | if ((y & 1) != 0) continue; |
| 243 | 245 | break y * 2; |
| ... | ... | @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { |
| 310 | 312 | |
| 311 | 313 | const slice: []const u8 = "blah"; |
| 312 | 314 | var start: usize = 0; |
| 315 | _ = &start; | |
| 313 | 316 | |
| 314 | 317 | for (slice, start..4, 1..5) |a, b, c| { |
| 315 | 318 | if (a == 'b') { |
| ... | ... | @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { |
| 394 | 397 | |
| 395 | 398 | const comptime_slice = "hello"; |
| 396 | 399 | var runtime_i: usize = 3; |
| 400 | _ = &runtime_i; | |
| 397 | 401 | |
| 398 | 402 | const S = struct { |
| 399 | 403 | var ok: usize = 0; |
| ... | ... | @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { |
| 424 | 428 | |
| 425 | 429 | var runtime_slice = "hello"; |
| 426 | 430 | var runtime_i: usize = 3; |
| 431 | _ = &runtime_i; | |
| 427 | 432 | |
| 428 | 433 | const S = struct { |
| 429 | 434 | var ok: usize = 0; |
| ... | ... | @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { |
| 484 | 489 | |
| 485 | 490 | { |
| 486 | 491 | var cond = false; |
| 487 | var opt = for (0..1) |_| { | |
| 492 | _ = &cond; | |
| 493 | const opt = for (0..1) |_| { | |
| 488 | 494 | if (cond) break cond; |
| 489 | 495 | } else null; |
| 490 | 496 | try expectEqual(@as(?bool, null), opt); |
| 491 | 497 | } |
| 492 | 498 | { |
| 493 | 499 | var cond = true; |
| 494 | var opt = for (0..1) |_| { | |
| 500 | _ = &cond; | |
| 501 | const opt = for (0..1) |_| { | |
| 495 | 502 | if (cond) break cond; |
| 496 | 503 | } else null; |
| 497 | 504 | try expectEqual(@as(?bool, true), opt); |
test/behavior/generics.zig+2| ... | ... | @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { |
| 102 | 102 | |
| 103 | 103 | fn SimpleList(comptime L: usize) type { |
| 104 | 104 | var mutable_T = u8; |
| 105 | _ = &mutable_T; | |
| 105 | 106 | const T = mutable_T; |
| 106 | 107 | return struct { |
| 107 | 108 | array: [L]T, |
| ... | ... | @@ -238,6 +239,7 @@ test "function parameter is generic" { |
| 238 | 239 | } |
| 239 | 240 | }; |
| 240 | 241 | var rng: u32 = 2; |
| 242 | _ = &rng; | |
| 241 | 243 | S.init(rng, S.fill); |
| 242 | 244 | } |
| 243 | 245 |
test/behavior/if.zig+12-5| ... | ... | @@ -61,6 +61,7 @@ test "unwrap mutable global var" { |
| 61 | 61 | test "labeled break inside comptime if inside runtime if" { |
| 62 | 62 | var answer: i32 = 0; |
| 63 | 63 | var c = true; |
| 64 | _ = &c; | |
| 64 | 65 | if (c) { |
| 65 | 66 | answer = if (true) blk: { |
| 66 | 67 | break :blk @as(i32, 42); |
| ... | ... | @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { |
| 73 | 74 | const Num = enum { One, Two }; |
| 74 | 75 | |
| 75 | 76 | var t = true; |
| 77 | _ = &t; | |
| 76 | 78 | const x = if (t) Num.Two else unreachable; |
| 77 | 79 | try expect(x == .Two); |
| 78 | 80 | } |
| ... | ... | @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { |
| 103 | 105 | try expect(x == 2); |
| 104 | 106 | |
| 105 | 107 | var b = true; |
| 108 | _ = &b; | |
| 106 | 109 | const y: i32 = if (b) 1 else 2; |
| 107 | 110 | try expect(y == 1); |
| 108 | 111 | } |
| ... | ... | @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { |
| 118 | 121 | |
| 119 | 122 | var self: []const u8 = "abcdef"; |
| 120 | 123 | var index: usize = 0; |
| 121 | var left_index = (index << 1) + 1; | |
| 122 | var right_index = left_index + 1; | |
| 123 | var left = if (left_index < self.len) self[left_index] else null; | |
| 124 | var right = if (right_index < self.len) self[right_index] else null; | |
| 124 | _ = .{ &self, &index }; | |
| 125 | const left_index = (index << 1) + 1; | |
| 126 | const right_index = left_index + 1; | |
| 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 | 129 | try expect(left_index < self.len); |
| 126 | 130 | try expect(right_index < self.len); |
| 127 | 131 | try expect(left.? == 98); |
| ... | ... | @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti |
| 135 | 139 | |
| 136 | 140 | const A = struct { b: u64, c: u64 }; |
| 137 | 141 | var d: bool = true; |
| 142 | _ = &d; | |
| 138 | 143 | const e = if (d) A{ .b = 15, .c = 30 } else null; |
| 139 | 144 | try expect(e != null); |
| 140 | 145 | } |
| ... | ... | @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti |
| 142 | 147 | test "result location with inferred type ends up being pointer to comptime_int" { |
| 143 | 148 | var a: ?u32 = 1234; |
| 144 | 149 | var b: u32 = 2000; |
| 145 | var c = if (a) |d| blk: { | |
| 150 | _ = .{ &a, &b }; | |
| 151 | const c = if (a) |d| blk: { | |
| 146 | 152 | if (d < b) break :blk @as(u32, 1); |
| 147 | 153 | break :blk 0; |
| 148 | 154 | } else @as(u32, 0); |
| ... | ... | @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" |
| 152 | 158 | test "if-@as-if chain" { |
| 153 | 159 | var fast = true; |
| 154 | 160 | var very_fast = false; |
| 161 | _ = .{ &fast, &very_fast }; | |
| 155 | 162 | |
| 156 | 163 | const num_frames = if (fast) |
| 157 | 164 | @as(u32, if (very_fast) 16 else 4) |
test/behavior/inline_switch.zig+8| ... | ... | @@ -22,6 +22,7 @@ test "inline prong ranges" { |
| 22 | 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 23 | 23 | |
| 24 | 24 | var x: usize = 0; |
| 25 | _ = &x; | |
| 25 | 26 | switch (x) { |
| 26 | 27 | inline 0...20, 24 => |item| { |
| 27 | 28 | if (item > 25) @compileError("bad"); |
| ... | ... | @@ -36,6 +37,7 @@ test "inline switch enums" { |
| 36 | 37 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 37 | 38 | |
| 38 | 39 | var x: E = .a; |
| 40 | _ = &x; | |
| 39 | 41 | switch (x) { |
| 40 | 42 | inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), |
| 41 | 43 | inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), |
| ... | ... | @@ -49,6 +51,7 @@ test "inline switch unions" { |
| 49 | 51 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 50 | 52 | |
| 51 | 53 | var x: U = .a; |
| 54 | _ = &x; | |
| 52 | 55 | switch (x) { |
| 53 | 56 | inline .a, .b => |aorb, tag| { |
| 54 | 57 | if (tag == .a) { |
| ... | ... | @@ -74,6 +77,7 @@ test "inline else bool" { |
| 74 | 77 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 75 | 78 | |
| 76 | 79 | var a = true; |
| 80 | _ = &a; | |
| 77 | 81 | switch (a) { |
| 78 | 82 | true => {}, |
| 79 | 83 | inline else => |val| if (val != false) @compileError("bad"), |
| ... | ... | @@ -86,6 +90,7 @@ test "inline else error" { |
| 86 | 90 | |
| 87 | 91 | const Err = error{ a, b, c }; |
| 88 | 92 | var a = Err.a; |
| 93 | _ = &a; | |
| 89 | 94 | switch (a) { |
| 90 | 95 | error.a => {}, |
| 91 | 96 | inline else => |val| comptime if (val == error.a) @compileError("bad"), |
| ... | ... | @@ -98,6 +103,7 @@ test "inline else enum" { |
| 98 | 103 | |
| 99 | 104 | const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; |
| 100 | 105 | var a: E2 = .a; |
| 106 | _ = &a; | |
| 101 | 107 | switch (a) { |
| 102 | 108 | .a, .b => {}, |
| 103 | 109 | inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), |
| ... | ... | @@ -109,6 +115,7 @@ test "inline else int with gaps" { |
| 109 | 115 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 110 | 116 | |
| 111 | 117 | var a: u8 = 0; |
| 118 | _ = &a; | |
| 112 | 119 | switch (a) { |
| 113 | 120 | 1...125, 128...254 => {}, |
| 114 | 121 | inline else => |val| { |
| ... | ... | @@ -126,6 +133,7 @@ test "inline else int all values" { |
| 126 | 133 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 127 | 134 | |
| 128 | 135 | var a: u2 = 0; |
| 136 | _ = &a; | |
| 129 | 137 | switch (a) { |
| 130 | 138 | inline else => |val| { |
| 131 | 139 | if (val != 0 and |
test/behavior/int128.zig+3| ... | ... | @@ -39,6 +39,7 @@ test "undefined 128 bit int" { |
| 39 | 39 | |
| 40 | 40 | var undef: u128 = undefined; |
| 41 | 41 | var undef_signed: i128 = undefined; |
| 42 | _ = .{ &undef, &undef_signed }; | |
| 42 | 43 | try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); |
| 43 | 44 | } |
| 44 | 45 | |
| ... | ... | @@ -73,6 +74,7 @@ test "truncate int128" { |
| 73 | 74 | |
| 74 | 75 | { |
| 75 | 76 | var buff: u128 = maxInt(u128); |
| 77 | _ = &buff; | |
| 76 | 78 | try expect(@as(u64, @truncate(buff)) == maxInt(u64)); |
| 77 | 79 | try expect(@as(u90, @truncate(buff)) == maxInt(u90)); |
| 78 | 80 | try expect(@as(u128, @truncate(buff)) == maxInt(u128)); |
| ... | ... | @@ -80,6 +82,7 @@ test "truncate int128" { |
| 80 | 82 | |
| 81 | 83 | { |
| 82 | 84 | var buff: i128 = maxInt(i128); |
| 85 | _ = &buff; | |
| 83 | 86 | try expect(@as(i64, @truncate(buff)) == -1); |
| 84 | 87 | try expect(@as(i90, @truncate(buff)) == -1); |
| 85 | 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 | 30 | const max = maxInt(T); |
| 31 | 31 | |
| 32 | 32 | var runtime_val: T = undefined; |
| 33 | _ = &runtime_val; | |
| 33 | 34 | |
| 34 | 35 | if (min > runtime_val) @compileError("analyzed impossible branch"); |
| 35 | 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 | 100 | { |
| 101 | 101 | var numerator: u256 = 99999999999999999997315645440; |
| 102 | 102 | var divisor: u256 = 10000000000000000000000000000; |
| 103 | _ = .{ &numerator, &divisor }; | |
| 103 | 104 | try expect(numerator / divisor == 9); |
| 104 | 105 | } |
| 105 | 106 | { |
| 106 | 107 | var numerator: u256 = 99999999999999999999000000000000000000000; |
| 107 | 108 | var divisor: u256 = 10000000000000000000000000000000000000000; |
| 109 | _ = .{ &numerator, &divisor }; | |
| 108 | 110 | try expect(numerator / divisor == 9); |
| 109 | 111 | } |
| 110 | 112 | } |
test/behavior/math.zig+53-5| ... | ... | @@ -624,7 +624,8 @@ const DivResult = struct { |
| 624 | 624 | |
| 625 | 625 | test "bit shift a u1" { |
| 626 | 626 | var x: u1 = 1; |
| 627 | var y = x << 0; | |
| 627 | _ = &x; | |
| 628 | const y = x << 0; | |
| 628 | 629 | try expect(y == 1); |
| 629 | 630 | } |
| 630 | 631 | |
| ... | ... | @@ -692,7 +693,8 @@ test "128-bit multiplication" { |
| 692 | 693 | { |
| 693 | 694 | var a: u128 = 0xffffffffffffffff; |
| 694 | 695 | var b: u128 = 100; |
| 695 | var c = a * b; | |
| 696 | _ = .{ &a, &b }; | |
| 697 | const c = a * b; | |
| 696 | 698 | try expect(c == 0x63ffffffffffffff9c); |
| 697 | 699 | } |
| 698 | 700 | } |
| ... | ... | @@ -704,18 +706,21 @@ test "@addWithOverflow" { |
| 704 | 706 | |
| 705 | 707 | { |
| 706 | 708 | var a: u8 = 250; |
| 709 | _ = &a; | |
| 707 | 710 | const ov = @addWithOverflow(a, 100); |
| 708 | 711 | try expect(ov[0] == 94); |
| 709 | 712 | try expect(ov[1] == 1); |
| 710 | 713 | } |
| 711 | 714 | { |
| 712 | 715 | var a: u8 = 100; |
| 716 | _ = &a; | |
| 713 | 717 | const ov = @addWithOverflow(a, 150); |
| 714 | 718 | try expect(ov[0] == 250); |
| 715 | 719 | try expect(ov[1] == 0); |
| 716 | 720 | } |
| 717 | 721 | { |
| 718 | 722 | var a: u8 = 200; |
| 723 | _ = &a; | |
| 719 | 724 | var b: u8 = 99; |
| 720 | 725 | var ov = @addWithOverflow(a, b); |
| 721 | 726 | try expect(ov[0] == 43); |
| ... | ... | @@ -729,6 +734,7 @@ test "@addWithOverflow" { |
| 729 | 734 | { |
| 730 | 735 | var a: usize = 6; |
| 731 | 736 | var b: usize = 6; |
| 737 | _ = .{ &a, &b }; | |
| 732 | 738 | const ov = @addWithOverflow(a, b); |
| 733 | 739 | try expect(ov[0] == 12); |
| 734 | 740 | try expect(ov[1] == 0); |
| ... | ... | @@ -737,6 +743,7 @@ test "@addWithOverflow" { |
| 737 | 743 | { |
| 738 | 744 | var a: isize = -6; |
| 739 | 745 | var b: isize = -6; |
| 746 | _ = .{ &a, &b }; | |
| 740 | 747 | const ov = @addWithOverflow(a, b); |
| 741 | 748 | try expect(ov[0] == -12); |
| 742 | 749 | try expect(ov[1] == 0); |
| ... | ... | @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { |
| 772 | 779 | |
| 773 | 780 | { |
| 774 | 781 | var a: u8 = 86; |
| 782 | _ = &a; | |
| 775 | 783 | const ov = @mulWithOverflow(a, 3); |
| 776 | 784 | try expect(ov[0] == 2); |
| 777 | 785 | try expect(ov[1] == 1); |
| 778 | 786 | } |
| 779 | 787 | { |
| 780 | 788 | var a: u8 = 85; |
| 789 | _ = &a; | |
| 781 | 790 | const ov = @mulWithOverflow(a, 3); |
| 782 | 791 | try expect(ov[0] == 255); |
| 783 | 792 | try expect(ov[1] == 0); |
| 784 | 793 | } |
| 785 | 794 | |
| 786 | 795 | var a: u8 = 123; |
| 796 | _ = &a; | |
| 787 | 797 | var b: u8 = 2; |
| 788 | 798 | var ov = @mulWithOverflow(a, b); |
| 789 | 799 | try expect(ov[0] == 246); |
| ... | ... | @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { |
| 802 | 812 | |
| 803 | 813 | { |
| 804 | 814 | var a: u5 = 3; |
| 815 | _ = &a; | |
| 805 | 816 | var b: u5 = 10; |
| 806 | 817 | var ov = @mulWithOverflow(a, b); |
| 807 | 818 | try expect(ov[0] == 30); |
| ... | ... | @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { |
| 815 | 826 | |
| 816 | 827 | { |
| 817 | 828 | var a: i5 = 3; |
| 829 | _ = &a; | |
| 818 | 830 | var b: i5 = -5; |
| 819 | 831 | var ov = @mulWithOverflow(a, b); |
| 820 | 832 | try expect(ov[0] == -15); |
| ... | ... | @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { |
| 828 | 840 | |
| 829 | 841 | { |
| 830 | 842 | var a: u8 = 3; |
| 843 | _ = &a; | |
| 831 | 844 | var b: u8 = 85; |
| 832 | 845 | |
| 833 | 846 | var ov = @mulWithOverflow(a, b); |
| ... | ... | @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { |
| 842 | 855 | |
| 843 | 856 | { |
| 844 | 857 | var a: i8 = 3; |
| 858 | _ = &a; | |
| 845 | 859 | var b: i8 = -42; |
| 846 | 860 | var ov = @mulWithOverflow(a, b); |
| 847 | 861 | try expect(ov[0] == -126); |
| ... | ... | @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { |
| 855 | 869 | |
| 856 | 870 | { |
| 857 | 871 | var a: u14 = 3; |
| 872 | _ = &a; | |
| 858 | 873 | var b: u14 = 0x1555; |
| 859 | 874 | var ov = @mulWithOverflow(a, b); |
| 860 | 875 | try expect(ov[0] == 0x3fff); |
| ... | ... | @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { |
| 868 | 883 | |
| 869 | 884 | { |
| 870 | 885 | var a: i14 = 3; |
| 886 | _ = &a; | |
| 871 | 887 | var b: i14 = -0xaaa; |
| 872 | 888 | var ov = @mulWithOverflow(a, b); |
| 873 | 889 | try expect(ov[0] == -0x1ffe); |
| ... | ... | @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { |
| 880 | 896 | |
| 881 | 897 | { |
| 882 | 898 | var a: u16 = 3; |
| 899 | _ = &a; | |
| 883 | 900 | var b: u16 = 0x5555; |
| 884 | 901 | var ov = @mulWithOverflow(a, b); |
| 885 | 902 | try expect(ov[0] == 0xffff); |
| ... | ... | @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { |
| 893 | 910 | |
| 894 | 911 | { |
| 895 | 912 | var a: i16 = 3; |
| 913 | _ = &a; | |
| 896 | 914 | var b: i16 = -0x2aaa; |
| 897 | 915 | var ov = @mulWithOverflow(a, b); |
| 898 | 916 | try expect(ov[0] == -0x7ffe); |
| ... | ... | @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { |
| 906 | 924 | |
| 907 | 925 | { |
| 908 | 926 | var a: u30 = 3; |
| 927 | _ = &a; | |
| 909 | 928 | var b: u30 = 0x15555555; |
| 910 | 929 | var ov = @mulWithOverflow(a, b); |
| 911 | 930 | try expect(ov[0] == 0x3fffffff); |
| ... | ... | @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { |
| 919 | 938 | |
| 920 | 939 | { |
| 921 | 940 | var a: i30 = 3; |
| 941 | _ = &a; | |
| 922 | 942 | var b: i30 = -0xaaaaaaa; |
| 923 | 943 | var ov = @mulWithOverflow(a, b); |
| 924 | 944 | try expect(ov[0] == -0x1ffffffe); |
| ... | ... | @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { |
| 932 | 952 | |
| 933 | 953 | { |
| 934 | 954 | var a: u32 = 3; |
| 955 | _ = &a; | |
| 935 | 956 | var b: u32 = 0x55555555; |
| 936 | 957 | var ov = @mulWithOverflow(a, b); |
| 937 | 958 | try expect(ov[0] == 0xffffffff); |
| ... | ... | @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { |
| 945 | 966 | |
| 946 | 967 | { |
| 947 | 968 | var a: i32 = 3; |
| 969 | _ = &a; | |
| 948 | 970 | var b: i32 = -0x2aaaaaaa; |
| 949 | 971 | var ov = @mulWithOverflow(a, b); |
| 950 | 972 | try expect(ov[0] == -0x7ffffffe); |
| ... | ... | @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 967 | 989 | |
| 968 | 990 | { |
| 969 | 991 | var a: u62 = 3; |
| 992 | _ = &a; | |
| 970 | 993 | var b: u62 = 0x1555555555555555; |
| 971 | 994 | var ov = @mulWithOverflow(a, b); |
| 972 | 995 | try expect(ov[0] == 0x3fffffffffffffff); |
| ... | ... | @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 980 | 1003 | |
| 981 | 1004 | { |
| 982 | 1005 | var a: i62 = 3; |
| 1006 | _ = &a; | |
| 983 | 1007 | var b: i62 = -0xaaaaaaaaaaaaaaa; |
| 984 | 1008 | var ov = @mulWithOverflow(a, b); |
| 985 | 1009 | try expect(ov[0] == -0x1ffffffffffffffe); |
| ... | ... | @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 993 | 1017 | |
| 994 | 1018 | { |
| 995 | 1019 | var a: u64 = 3; |
| 1020 | _ = &a; | |
| 996 | 1021 | var b: u64 = 0x5555555555555555; |
| 997 | 1022 | var ov = @mulWithOverflow(a, b); |
| 998 | 1023 | try expect(ov[0] == 0xffffffffffffffff); |
| ... | ... | @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 1006 | 1031 | |
| 1007 | 1032 | { |
| 1008 | 1033 | var a: i64 = 3; |
| 1034 | _ = &a; | |
| 1009 | 1035 | var b: i64 = -0x2aaaaaaaaaaaaaaa; |
| 1010 | 1036 | var ov = @mulWithOverflow(a, b); |
| 1011 | 1037 | try expect(ov[0] == -0x7ffffffffffffffe); |
| ... | ... | @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { |
| 1025 | 1051 | |
| 1026 | 1052 | { |
| 1027 | 1053 | var a: u8 = 1; |
| 1054 | _ = &a; | |
| 1028 | 1055 | const ov = @subWithOverflow(a, 2); |
| 1029 | 1056 | try expect(ov[0] == 255); |
| 1030 | 1057 | try expect(ov[1] == 1); |
| 1031 | 1058 | } |
| 1032 | 1059 | { |
| 1033 | 1060 | var a: u8 = 1; |
| 1061 | _ = &a; | |
| 1034 | 1062 | const ov = @subWithOverflow(a, 1); |
| 1035 | 1063 | try expect(ov[0] == 0); |
| 1036 | 1064 | try expect(ov[1] == 0); |
| ... | ... | @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { |
| 1038 | 1066 | |
| 1039 | 1067 | { |
| 1040 | 1068 | var a: u8 = 1; |
| 1069 | _ = &a; | |
| 1041 | 1070 | var b: u8 = 2; |
| 1042 | 1071 | var ov = @subWithOverflow(a, b); |
| 1043 | 1072 | try expect(ov[0] == 255); |
| ... | ... | @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { |
| 1051 | 1080 | { |
| 1052 | 1081 | var a: usize = 6; |
| 1053 | 1082 | var b: usize = 6; |
| 1083 | _ = .{ &a, &b }; | |
| 1054 | 1084 | const ov = @subWithOverflow(a, b); |
| 1055 | 1085 | try expect(ov[0] == 0); |
| 1056 | 1086 | try expect(ov[1] == 0); |
| ... | ... | @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { |
| 1059 | 1089 | { |
| 1060 | 1090 | var a: isize = -6; |
| 1061 | 1091 | var b: isize = -6; |
| 1092 | _ = .{ &a, &b }; | |
| 1062 | 1093 | const ov = @subWithOverflow(a, b); |
| 1063 | 1094 | try expect(ov[0] == 0); |
| 1064 | 1095 | try expect(ov[1] == 0); |
| ... | ... | @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { |
| 1072 | 1103 | |
| 1073 | 1104 | { |
| 1074 | 1105 | var a: u4 = 2; |
| 1106 | _ = &a; | |
| 1075 | 1107 | var b: u2 = 1; |
| 1076 | 1108 | var ov = @shlWithOverflow(a, b); |
| 1077 | 1109 | try expect(ov[0] == 4); |
| ... | ... | @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { |
| 1085 | 1117 | |
| 1086 | 1118 | { |
| 1087 | 1119 | var a: i9 = 127; |
| 1120 | _ = &a; | |
| 1088 | 1121 | var b: u4 = 1; |
| 1089 | 1122 | var ov = @shlWithOverflow(a, b); |
| 1090 | 1123 | try expect(ov[0] == 254); |
| ... | ... | @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { |
| 1108 | 1141 | } |
| 1109 | 1142 | { |
| 1110 | 1143 | var a: u16 = 0b0000_0000_0000_0011; |
| 1144 | _ = &a; | |
| 1111 | 1145 | var b: u4 = 15; |
| 1112 | 1146 | var ov = @shlWithOverflow(a, b); |
| 1113 | 1147 | try expect(ov[0] == 0b1000_0000_0000_0000); |
| ... | ... | @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { |
| 1124 | 1158 | |
| 1125 | 1159 | { |
| 1126 | 1160 | var a: u0 = 0; |
| 1161 | _ = &a; | |
| 1127 | 1162 | const ov = @addWithOverflow(a, 0); |
| 1128 | 1163 | try expect(ov[1] == 0); |
| 1129 | 1164 | try expect(ov[1] == 0); |
| 1130 | 1165 | } |
| 1131 | 1166 | { |
| 1132 | 1167 | var a: u0 = 0; |
| 1168 | _ = &a; | |
| 1133 | 1169 | const ov = @subWithOverflow(a, 0); |
| 1134 | 1170 | try expect(ov[1] == 0); |
| 1135 | 1171 | try expect(ov[1] == 0); |
| 1136 | 1172 | } |
| 1137 | 1173 | { |
| 1138 | 1174 | var a: u0 = 0; |
| 1175 | _ = &a; | |
| 1139 | 1176 | const ov = @mulWithOverflow(a, 0); |
| 1140 | 1177 | try expect(ov[1] == 0); |
| 1141 | 1178 | try expect(ov[1] == 0); |
| 1142 | 1179 | } |
| 1143 | 1180 | { |
| 1144 | 1181 | var a: u0 = 0; |
| 1182 | _ = &a; | |
| 1145 | 1183 | const ov = @shlWithOverflow(a, 0); |
| 1146 | 1184 | try expect(ov[1] == 0); |
| 1147 | 1185 | try expect(ov[1] == 0); |
| ... | ... | @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and |
| 1157 | 1195 | try expect(-6 % 3 == 0); |
| 1158 | 1196 | |
| 1159 | 1197 | var undef: i32 = undefined; |
| 1198 | _ = &undef; | |
| 1160 | 1199 | if (0 % undef != 0) { |
| 1161 | 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 | 1222 | fn doTheTest() !void { |
| 1184 | 1223 | { |
| 1185 | 1224 | var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; |
| 1225 | _ = &f; | |
| 1186 | 1226 | try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); |
| 1187 | 1227 | } |
| 1188 | 1228 | { |
| 1189 | 1229 | var f: f128 = 0x1.edcb34a235253948765432134674fp-1; |
| 1230 | _ = &f; | |
| 1190 | 1231 | try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even |
| 1191 | 1232 | } |
| 1192 | 1233 | { |
| 1193 | 1234 | var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; |
| 1235 | _ = &f; | |
| 1194 | 1236 | try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); |
| 1195 | 1237 | } |
| 1196 | 1238 | { |
| 1197 | 1239 | var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; |
| 1240 | _ = &f; | |
| 1198 | 1241 | try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); |
| 1199 | 1242 | } |
| 1200 | 1243 | const exp2ft = [_]f64{ |
| ... | ... | @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { |
| 1294 | 1337 | fn doTheTest() !void { |
| 1295 | 1338 | var x: u0 = 0; |
| 1296 | 1339 | var y: u0 = 0; |
| 1340 | _ = .{ &x, &y }; | |
| 1297 | 1341 | try expectEqual(@as(u0, 0), x << 0); |
| 1298 | 1342 | try expectEqual(@as(u0, 0), x >> 0); |
| 1299 | 1343 | try expectEqual(@as(u0, 0), x << y); |
| ... | ... | @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { |
| 1310 | 1354 | |
| 1311 | 1355 | test "comptime float rem int" { |
| 1312 | 1356 | comptime { |
| 1313 | var x = @as(f32, 1) % 2; | |
| 1357 | const x = @as(f32, 1) % 2; | |
| 1314 | 1358 | try expect(x == 1.0); |
| 1315 | 1359 | } |
| 1316 | 1360 | } |
| ... | ... | @@ -1511,7 +1555,8 @@ test "vector integer addition" { |
| 1511 | 1555 | fn doTheTest() !void { |
| 1512 | 1556 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 1513 | 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 | 1560 | var result_array: [4]i32 = result; |
| 1516 | 1561 | const expected = [_]i32{ 6, 8, 10, 12 }; |
| 1517 | 1562 | try expectEqualSlices(i32, &expected, &result_array); |
| ... | ... | @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { |
| 1552 | 1597 | fn testNanEqNan(comptime F: type) !void { |
| 1553 | 1598 | var nan1 = math.nan(F); |
| 1554 | 1599 | var nan2 = math.nan(F); |
| 1600 | _ = .{ &nan1, &nan2 }; | |
| 1555 | 1601 | try expect(nan1 != nan2); |
| 1556 | 1602 | try expect(!(nan1 == nan2)); |
| 1557 | 1603 | try expect(!(nan1 > nan2)); |
| ... | ... | @@ -1571,6 +1617,7 @@ test "vector comparison" { |
| 1571 | 1617 | fn doTheTest() !void { |
| 1572 | 1618 | var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; |
| 1573 | 1619 | var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; |
| 1620 | _ = .{ &a, &b }; | |
| 1574 | 1621 | try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); |
| 1575 | 1622 | try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); |
| 1576 | 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 | 1656 | fn testOne(comptime T: type) !void { |
| 1610 | 1657 | const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 1611 | 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 | 1661 | // Ensure the sign bit is set. |
| 1614 | 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 | 15 | var x: i32 = 10; |
| 16 | 16 | var y: f32 = 0.68; |
| 17 | 17 | var nan: f32 = std.math.nan(f32); |
| 18 | _ = .{ &x, &y, &nan }; | |
| 18 | 19 | try expect(@as(i32, 10) == @max(@as(i32, -3), x)); |
| 19 | 20 | try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); |
| 20 | 21 | try expect(y == @max(nan, y)); |
| ... | ... | @@ -38,17 +39,20 @@ test "@max on vectors" { |
| 38 | 39 | fn doTheTest() !void { |
| 39 | 40 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 40 | 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 | 44 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); |
| 43 | 45 | |
| 44 | 46 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; |
| 45 | 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 | 50 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); |
| 48 | 51 | |
| 49 | 52 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; |
| 50 | 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 | 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 | 70 | var x: i32 = 10; |
| 67 | 71 | var y: f32 = 0.68; |
| 68 | 72 | var nan: f32 = std.math.nan(f32); |
| 73 | _ = .{ &x, &y, &nan }; | |
| 69 | 74 | try expect(@as(i32, -3) == @min(@as(i32, -3), x)); |
| 70 | 75 | try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); |
| 71 | 76 | try expect(y == @min(nan, y)); |
| ... | ... | @@ -89,17 +94,20 @@ test "@min for vectors" { |
| 89 | 94 | fn doTheTest() !void { |
| 90 | 95 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 91 | 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 | 99 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); |
| 94 | 100 | |
| 95 | 101 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; |
| 96 | 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 | 105 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); |
| 99 | 106 | |
| 100 | 107 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; |
| 101 | 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 | 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 | 127 | fn doTheTest(comptime T: type) !void { |
| 120 | 128 | var x: T = -3.14; |
| 121 | 129 | var y: T = 5.27; |
| 130 | _ = .{ &x, &y }; | |
| 122 | 131 | try expectEqual(x, @min(x, y)); |
| 123 | 132 | try expectEqual(x, @min(y, x)); |
| 124 | 133 | try expectEqual(y, @max(x, y)); |
| ... | ... | @@ -126,6 +135,7 @@ test "@min/max for floats" { |
| 126 | 135 | |
| 127 | 136 | if (T != comptime_float) { |
| 128 | 137 | var nan: T = std.math.nan(T); |
| 138 | _ = &nan; | |
| 129 | 139 | try expectEqual(y, @max(nan, y)); |
| 130 | 140 | try expectEqual(y, @max(y, nan)); |
| 131 | 141 | } |
| ... | ... | @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { |
| 175 | 185 | var x: u16 = 20; |
| 176 | 186 | const y = 30; |
| 177 | 187 | var z: u32 = 100; |
| 188 | _ = .{ &x, &z }; | |
| 178 | 189 | const min = @min(x, y, z); |
| 179 | 190 | const max = @max(x, y, z); |
| 180 | 191 | try expectEqual(x, min); |
| ... | ... | @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { |
| 194 | 205 | var x: @Vector(2, u16) = .{ 140, 40 }; |
| 195 | 206 | const y: @Vector(2, u64) = .{ 5, 100 }; |
| 196 | 207 | var z: @Vector(2, u32) = .{ 10, 300 }; |
| 208 | _ = .{ &x, &z }; | |
| 197 | 209 | const min = @min(x, y, z); |
| 198 | 210 | const max = @max(x, y, z); |
| 199 | 211 | try expectEqual(@Vector(2, u32){ 5, 40 }, min); |
| ... | ... | @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { |
| 224 | 236 | var x: u16 = 123; |
| 225 | 237 | var y: u32 = 456; |
| 226 | 238 | var z: u8 = 10; |
| 239 | _ = .{ &x, &y, &z }; | |
| 227 | 240 | |
| 228 | 241 | const min = @min(x, y, z); |
| 229 | 242 | const max = @max(x, y, z); |
| ... | ... | @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { |
| 246 | 259 | var x: @Vector(2, u16) = .{ 30, 67 }; |
| 247 | 260 | var y: @Vector(2, u32) = .{ 20, 500 }; |
| 248 | 261 | var z: @Vector(2, u8) = .{ 60, 15 }; |
| 262 | _ = .{ &x, &y, &z }; | |
| 249 | 263 | |
| 250 | 264 | const min = @min(x, y, z); |
| 251 | 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 | 277 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 264 | 278 | |
| 265 | 279 | var x: u32 = 1_000_000; |
| 280 | _ = &x; | |
| 266 | 281 | const y: u16 = undefined; |
| 267 | 282 | // y is comptime-known, but is undef, so bounds cannot be refined using its value |
| 268 | 283 | |
| ... | ... | @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known |
| 285 | 300 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; |
| 286 | 301 | |
| 287 | 302 | var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; |
| 303 | _ = &x; | |
| 288 | 304 | const y: @Vector(2, u16) = .{ 10, undefined }; |
| 289 | 305 | // y is comptime-known, but an element is undef, so bounds cannot be refined using its value |
| 290 | 306 | |
| ... | ... | @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known |
| 302 | 318 | test "@min/@max of signed and unsigned runtime integers" { |
| 303 | 319 | var x: i32 = -1; |
| 304 | 320 | var y: u31 = 1; |
| 321 | _ = .{ &x, &y }; | |
| 305 | 322 | |
| 306 | 323 | const min = @min(x, y); |
| 307 | 324 | const max = @max(x, y); |
test/behavior/memcpy.zig+1| ... | ... | @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { |
| 57 | 57 | var str = "hello".*; |
| 58 | 58 | var buf: [5]u8 = undefined; |
| 59 | 59 | var len: usize = 5; |
| 60 | _ = &len; | |
| 60 | 61 | @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); |
| 61 | 62 | try expect(buf[0] == 'h'); |
| 62 | 63 | try expect(buf[1] == 'e'); |
test/behavior/memset.zig+5-2| ... | ... | @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { |
| 46 | 46 | // memset slice to non-undefined, ABI size == 1 |
| 47 | 47 | var array: [20]u8 = undefined; |
| 48 | 48 | var len = array.len; |
| 49 | var slice = array[0..len]; | |
| 49 | _ = &len; | |
| 50 | const slice = array[0..len]; | |
| 50 | 51 | @memset(slice, 'A'); |
| 51 | 52 | try expect(slice[0] == 'A'); |
| 52 | 53 | try expect(slice[11] == 'A'); |
| ... | ... | @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { |
| 56 | 57 | // memset slice to non-undefined, ABI size > 1 |
| 57 | 58 | var array: [20]u32 = undefined; |
| 58 | 59 | var len = array.len; |
| 59 | var slice = array[0..len]; | |
| 60 | _ = &len; | |
| 61 | const slice = array[0..len]; | |
| 60 | 62 | @memset(slice, 1234); |
| 61 | 63 | try expect(slice[0] == 1234); |
| 62 | 64 | try expect(slice[11] == 1234); |
| ... | ... | @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { |
| 111 | 113 | const A = [128]u64; |
| 112 | 114 | var buf: [5]A = undefined; |
| 113 | 115 | var runtime_known_element = [_]u64{0} ** 128; |
| 116 | _ = &runtime_known_element; | |
| 114 | 117 | @memset(&buf, runtime_known_element); |
| 115 | 118 | for (buf[0]) |elem| try expect(elem == 0); |
| 116 | 119 | for (buf[1]) |elem| try expect(elem == 0); |
test/behavior/muladd.zig+15-5| ... | ... | @@ -21,12 +21,14 @@ fn testMulAdd() !void { |
| 21 | 21 | var a: f32 = 5.5; |
| 22 | 22 | var b: f32 = 2.5; |
| 23 | 23 | var c: f32 = 6.25; |
| 24 | _ = .{ &a, &b, &c }; | |
| 24 | 25 | try expect(@mulAdd(f32, a, b, c) == 20); |
| 25 | 26 | } |
| 26 | 27 | { |
| 27 | 28 | var a: f64 = 5.5; |
| 28 | 29 | var b: f64 = 2.5; |
| 29 | 30 | var c: f64 = 6.25; |
| 31 | _ = .{ &a, &b, &c }; | |
| 30 | 32 | try expect(@mulAdd(f64, a, b, c) == 20); |
| 31 | 33 | } |
| 32 | 34 | } |
| ... | ... | @@ -46,6 +48,7 @@ fn testMulAdd16() !void { |
| 46 | 48 | var a: f16 = 5.5; |
| 47 | 49 | var b: f16 = 2.5; |
| 48 | 50 | var c: f16 = 6.25; |
| 51 | _ = .{ &a, &b, &c }; | |
| 49 | 52 | try expect(@mulAdd(f16, a, b, c) == 20); |
| 50 | 53 | } |
| 51 | 54 | |
| ... | ... | @@ -65,6 +68,7 @@ fn testMulAdd80() !void { |
| 65 | 68 | var a: f16 = 5.5; |
| 66 | 69 | var b: f80 = 2.5; |
| 67 | 70 | var c: f80 = 6.25; |
| 71 | _ = .{ &a, &b, &c }; | |
| 68 | 72 | try expect(@mulAdd(f80, a, b, c) == 20); |
| 69 | 73 | } |
| 70 | 74 | |
| ... | ... | @@ -84,6 +88,7 @@ fn testMulAdd128() !void { |
| 84 | 88 | var a: f16 = 5.5; |
| 85 | 89 | var b: f128 = 2.5; |
| 86 | 90 | var c: f128 = 6.25; |
| 91 | _ = .{ &a, &b, &c }; | |
| 87 | 92 | try expect(@mulAdd(f128, a, b, c) == 20); |
| 88 | 93 | } |
| 89 | 94 | |
| ... | ... | @@ -91,7 +96,8 @@ fn vector16() !void { |
| 91 | 96 | var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; |
| 92 | 97 | var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; |
| 93 | 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); | |
| 95 | 101 | |
| 96 | 102 | try expect(x[0] == 20); |
| 97 | 103 | try expect(x[1] == 20); |
| ... | ... | @@ -115,7 +121,8 @@ fn vector32() !void { |
| 115 | 121 | var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; |
| 116 | 122 | var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; |
| 117 | 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); | |
| 119 | 126 | |
| 120 | 127 | try expect(x[0] == 20); |
| 121 | 128 | try expect(x[1] == 20); |
| ... | ... | @@ -139,7 +146,8 @@ fn vector64() !void { |
| 139 | 146 | var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; |
| 140 | 147 | var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; |
| 141 | 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); | |
| 143 | 151 | |
| 144 | 152 | try expect(x[0] == 20); |
| 145 | 153 | try expect(x[1] == 20); |
| ... | ... | @@ -163,7 +171,8 @@ fn vector80() !void { |
| 163 | 171 | var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; |
| 164 | 172 | var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; |
| 165 | 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 | 176 | try expect(x[0] == 20); |
| 168 | 177 | try expect(x[1] == 20); |
| 169 | 178 | try expect(x[2] == 20); |
| ... | ... | @@ -187,7 +196,8 @@ fn vector128() !void { |
| 187 | 196 | var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; |
| 188 | 197 | var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; |
| 189 | 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); | |
| 191 | 201 | |
| 192 | 202 | try expect(x[0] == 20); |
| 193 | 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 | 134 | |
| 135 | 135 | const EmptyStruct = struct {}; |
| 136 | 136 | var x: ?*EmptyStruct = null; |
| 137 | _ = &x; | |
| 137 | 138 | try expect(x == null); |
| 138 | 139 | } |
| 139 | 140 |
test/behavior/optional.zig+13-6| ... | ... | @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { |
| 11 | 11 | |
| 12 | 12 | const S = struct { |
| 13 | 13 | fn entry() bool { |
| 14 | var x: i32 = 1234; | |
| 14 | const x: i32 = 1234; | |
| 15 | 15 | return foo(x); |
| 16 | 16 | } |
| 17 | 17 | |
| ... | ... | @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { |
| 29 | 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 30 | 30 | |
| 31 | 31 | var e = EmptyStruct{}; |
| 32 | var o: ?*EmptyStruct = &e; | |
| 32 | const o: ?*EmptyStruct = &e; | |
| 33 | 33 | try expect(o != null); |
| 34 | 34 | } |
| 35 | 35 | |
| ... | ... | @@ -63,6 +63,7 @@ test "optional with void type" { |
| 63 | 63 | x: ?void, |
| 64 | 64 | }; |
| 65 | 65 | var x = Foo{ .x = null }; |
| 66 | _ = &x; | |
| 66 | 67 | try expect(x.x == null); |
| 67 | 68 | } |
| 68 | 69 | |
| ... | ... | @@ -102,6 +103,7 @@ test "nested optional field in struct" { |
| 102 | 103 | var s = S1{ |
| 103 | 104 | .x = S2{ .y = 127 }, |
| 104 | 105 | }; |
| 106 | _ = &s; | |
| 105 | 107 | try expect(s.x.?.y == 127); |
| 106 | 108 | } |
| 107 | 109 | |
| ... | ... | @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { |
| 120 | 122 | var five: i32 = 5; |
| 121 | 123 | var int_n: ?i32 = null; |
| 122 | 124 | |
| 125 | _ = .{ &ten, &opt_ten, &five, &int_n }; | |
| 126 | ||
| 123 | 127 | try expect(int_n != ten); |
| 124 | 128 | try expect(opt_ten == ten); |
| 125 | 129 | try expect(opt_ten != five); |
| ... | ... | @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { |
| 208 | 212 | }; |
| 209 | 213 | }; |
| 210 | 214 | |
| 211 | var n = S.Node.new(); | |
| 215 | const n = S.Node.new(); | |
| 212 | 216 | try expect(n.data == null); |
| 213 | 217 | } |
| 214 | 218 | |
| ... | ... | @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { |
| 252 | 256 | const S = struct { |
| 253 | 257 | fn doTheTest() !void { |
| 254 | 258 | var y = Foo{}; |
| 255 | var z = y.thing(); | |
| 259 | const z = y.thing(); | |
| 256 | 260 | try expect(z != null); |
| 257 | 261 | } |
| 258 | 262 | |
| ... | ... | @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { |
| 425 | 429 | |
| 426 | 430 | fn foo() ?I { |
| 427 | 431 | var i: I = .{ .x = 1234 }; |
| 432 | _ = &i; | |
| 428 | 433 | return i; |
| 429 | 434 | } |
| 430 | 435 | }; |
| ... | ... | @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { |
| 450 | 455 | const Thing = struct { n: i32 }; |
| 451 | 456 | var a = false; |
| 452 | 457 | var b = false; |
| 458 | _ = .{ &a, &b }; | |
| 453 | 459 | |
| 454 | var result1 = if (a) | |
| 460 | const result1 = if (a) | |
| 455 | 461 | Thing{ .n = 1 } |
| 456 | 462 | else |
| 457 | 463 | null; |
| 458 | 464 | try expect(result1 == null); |
| 459 | 465 | try expect(@TypeOf(result1) == ?Thing); |
| 460 | 466 | |
| 461 | var result2 = if (a) | |
| 467 | const result2 = if (a) | |
| 462 | 468 | Thing{ .n = 0 } |
| 463 | 469 | else if (b) |
| 464 | 470 | Thing{ .n = 1 } |
| ... | ... | @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { |
| 486 | 492 | |
| 487 | 493 | test "variable of optional of noreturn" { |
| 488 | 494 | var null_opv: ?noreturn = null; |
| 495 | _ = &null_opv; | |
| 489 | 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 | 479 | y: u32, |
| 480 | 480 | }; |
| 481 | 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 | 483 | for (b_list) |b| { |
| 484 | var i = b.x.index; | |
| 485 | try expect(i == 123); | |
| 484 | try expect(b.x.index == 123); | |
| 486 | 485 | } |
| 487 | 486 | } |
| 488 | 487 | |
| ... | ... | @@ -770,6 +769,7 @@ test "nested packed struct field access test" { |
| 770 | 769 | }; |
| 771 | 770 | |
| 772 | 771 | var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; |
| 772 | _ = &arg; | |
| 773 | 773 | try std.testing.expect(arg.b.c == 1); |
| 774 | 774 | try std.testing.expect(arg.b.d == 2); |
| 775 | 775 | try std.testing.expect(arg.g.h == 6); |
| ... | ... | @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { |
| 790 | 790 | }; |
| 791 | 791 | |
| 792 | 792 | var k: u8 = 123; |
| 793 | _ = &k; | |
| 793 | 794 | var v: A = .{ |
| 794 | 795 | .p1 = .{ .a = k + 1, .b = k }, |
| 795 | 796 | .p2 = .{ .a = k + 1, .b = k }, |
| ... | ... | @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { |
| 833 | 834 | |
| 834 | 835 | fn doTheTest() !void { |
| 835 | 836 | var k: u8 = 123; |
| 837 | _ = &k; | |
| 836 | 838 | var v: A = .{ |
| 837 | 839 | .p1 = .{ .a = k + 1, .b = k }, |
| 838 | 840 | .p2 = .{ .a = k + 1, .b = k }, |
| ... | ... | @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { |
| 877 | 879 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 878 | 880 | |
| 879 | 881 | var z: u8 = 123; |
| 882 | _ = &z; | |
| 880 | 883 | try (packed struct { |
| 881 | 884 | x: u8, |
| 882 | 885 | pub fn m(s: @This()) !void { |
| ... | ... | @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { |
| 941 | 944 | |
| 942 | 945 | const T = packed struct { val: u8 }; |
| 943 | 946 | var val: u8 = 123; |
| 947 | _ = &val; | |
| 944 | 948 | const t = @as(u8, @bitCast(T{ .val = val })); |
| 945 | 949 | try expect(t == val); |
| 946 | 950 | } |
| ... | ... | @@ -976,7 +980,8 @@ test "store undefined to packed result location" { |
| 976 | 980 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 977 | 981 | |
| 978 | 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 | 985 | try expectEqual(x, s.x); |
| 981 | 986 | } |
| 982 | 987 | |
| ... | ... | @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init |
| 1004 | 1009 | } |
| 1005 | 1010 | }; |
| 1006 | 1011 | |
| 1007 | var s = S.init(true); | |
| 1012 | const s = S.init(true); | |
| 1008 | 1013 | // note: this bug is triggered by the == operator, expectEqual will hide it |
| 1009 | 1014 | try expect(@as(i2, 0) == s.ps.x); |
| 1010 | 1015 | try expect(@as(i2, 1) == s.ps.y); |
test/behavior/pointers.zig+37-23| ... | ... | @@ -11,7 +11,7 @@ test "dereference pointer" { |
| 11 | 11 | |
| 12 | 12 | fn testDerefPtr() !void { |
| 13 | 13 | var x: i32 = 1234; |
| 14 | var y = &x; | |
| 14 | const y = &x; | |
| 15 | 15 | y.* += 1; |
| 16 | 16 | try expect(x == 1235); |
| 17 | 17 | } |
| ... | ... | @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { |
| 53 | 53 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 54 | 54 | |
| 55 | 55 | var y: u8 = 11; |
| 56 | var x: [*c]u8 = &y; | |
| 57 | var z: *u8 = x; | |
| 56 | const x: [*c]u8 = &y; | |
| 57 | const z: *u8 = x; | |
| 58 | 58 | z.* += 1; |
| 59 | 59 | try expect(y == 12); |
| 60 | 60 | } |
| ... | ... | @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { |
| 74 | 74 | var ptr2: [*c]u8 = x; |
| 75 | 75 | var ptr3: [*c]u8 = 1; |
| 76 | 76 | var ptr4: [*c]u8 = y; |
| 77 | _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 }; | |
| 77 | 78 | |
| 78 | 79 | try expect(ptr == ptr2); |
| 79 | 80 | try expect(ptr3 == ptr4); |
| ... | ... | @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { |
| 88 | 89 | fn doTheTest() !void { |
| 89 | 90 | var ptr1: [*c]u32 = 0; |
| 90 | 91 | var ptr2 = ptr1 + 10; |
| 92 | _ = &ptr1; | |
| 91 | 93 | try expect(ptr1 == 0); |
| 92 | 94 | try expect(ptr1 >= 0); |
| 93 | 95 | try expect(ptr1 <= 0); |
| ... | ... | @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { |
| 125 | 127 | } |
| 126 | 128 | |
| 127 | 129 | test "peer type resolution with C pointers" { |
| 128 | var ptr_one: *u8 = undefined; | |
| 129 | var ptr_many: [*]u8 = undefined; | |
| 130 | var ptr_c: [*c]u8 = undefined; | |
| 130 | const ptr_one: *u8 = undefined; | |
| 131 | const ptr_many: [*]u8 = undefined; | |
| 132 | const ptr_c: [*c]u8 = undefined; | |
| 131 | 133 | var t = true; |
| 132 | var x1 = if (t) ptr_one else ptr_c; | |
| 133 | var x2 = if (t) ptr_many else ptr_c; | |
| 134 | var x3 = if (t) ptr_c else ptr_one; | |
| 135 | var x4 = if (t) ptr_c else ptr_many; | |
| 134 | _ = &t; | |
| 135 | const x1 = if (t) ptr_one else ptr_c; | |
| 136 | const x2 = if (t) ptr_many else ptr_c; | |
| 137 | const x3 = if (t) ptr_c else ptr_one; | |
| 138 | const x4 = if (t) ptr_c else ptr_many; | |
| 136 | 139 | try expect(@TypeOf(x1) == [*c]u8); |
| 137 | 140 | try expect(@TypeOf(x2) == [*c]u8); |
| 138 | 141 | try expect(@TypeOf(x3) == [*c]u8); |
| ... | ... | @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { |
| 141 | 144 | |
| 142 | 145 | test "peer type resolution with C pointer and const pointer" { |
| 143 | 146 | var ptr_c: [*c]u8 = undefined; |
| 144 | const ptr_const: u8 = undefined; | |
| 145 | try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8); | |
| 147 | var ptr_const: *const u8 = &undefined; | |
| 148 | _ = .{ &ptr_c, &ptr_const }; | |
| 149 | try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8); | |
| 146 | 150 | } |
| 147 | 151 | |
| 148 | 152 | 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 | 155 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 152 | 156 | |
| 153 | 157 | var slice: []const u8 = "aoeu"; |
| 158 | _ = &slice; | |
| 154 | 159 | const opt_many_ptr: ?[*]const u8 = slice.ptr; |
| 155 | 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 | 162 | try expect(c_ptr.*.* == 'a'); |
| 158 | 163 | ptr_opt_many_ptr = c_ptr; |
| 159 | 164 | try expect(ptr_opt_many_ptr.*.?[1] == 'o'); |
| ... | ... | @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { |
| 192 | 197 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 193 | 198 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 194 | 199 | |
| 195 | var ptr = @as([*]allowzero i32, @ptrFromInt(0)); | |
| 196 | var opt_ptr: ?[*]allowzero i32 = ptr; | |
| 200 | var ptr: [*]allowzero i32 = @ptrFromInt(0); | |
| 201 | const opt_ptr: ?[*]allowzero i32 = ptr; | |
| 197 | 202 | try expect(opt_ptr != null); |
| 198 | 203 | try expect(@intFromPtr(ptr) == 0); |
| 199 | 204 | var runtime_zero: usize = 0; |
| 205 | _ = &runtime_zero; | |
| 200 | 206 | var slice = ptr[runtime_zero..10]; |
| 201 | 207 | try comptime expect(@TypeOf(slice) == []allowzero i32); |
| 202 | 208 | try expect(@intFromPtr(&slice[5]) == 20); |
| ... | ... | @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { |
| 211 | 217 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 212 | 218 | |
| 213 | 219 | var x: [*c]i32 = null; |
| 220 | _ = &x; | |
| 214 | 221 | try expect(x == null); |
| 215 | 222 | try expect(null == x); |
| 216 | 223 | try expect(!(x != null)); |
| ... | ... | @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { |
| 236 | 243 | try comptime expect((y orelse ptr_othery) == ptr_othery); |
| 237 | 244 | |
| 238 | 245 | var n: i32 = 1234; |
| 239 | var x1: [*c]i32 = &n; | |
| 246 | const x1: [*c]i32 = &n; | |
| 240 | 247 | try expect(!(x1 == null)); |
| 241 | 248 | try expect(!(null == x1)); |
| 242 | 249 | try expect(x1 != null); |
| ... | ... | @@ -279,9 +286,9 @@ test "null terminated pointer" { |
| 279 | 286 | const S = struct { |
| 280 | 287 | fn doTheTest() !void { |
| 281 | 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)); | |
| 283 | var no_zero_ptr: [*]const u8 = zero_ptr; | |
| 284 | var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); | |
| 289 | const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero); | |
| 290 | const no_zero_ptr: [*]const u8 = zero_ptr; | |
| 291 | const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr); | |
| 285 | 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 | 303 | const S = struct { |
| 297 | 304 | fn doTheTest() !void { |
| 298 | 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 | 307 | try expect(ptr[4] == std.math.minInt(i32)); |
| 301 | 308 | } |
| 302 | 309 | }; |
| ... | ... | @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { |
| 317 | 324 | |
| 318 | 325 | fn doTheTest() !void { |
| 319 | 326 | var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; |
| 327 | _ = &ptr; | |
| 320 | 328 | 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 | 340 | const S = struct { |
| 333 | 341 | fn doTheTest() !void { |
| 334 | 342 | var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; |
| 343 | _ = &ptr; | |
| 335 | 344 | 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 | 357 | fn doTheTest() !void { |
| 349 | 358 | const inf_f32 = comptime std.math.inf(f32); |
| 350 | 359 | var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 360 | _ = &ptr; | |
| 351 | 361 | 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 | 376 | { |
| 367 | 377 | var ptr: [*]align(8) u32 = undefined; |
| 368 | 378 | var x: usize = 1; |
| 379 | _ = .{ &ptr, &x }; | |
| 369 | 380 | |
| 370 | 381 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); |
| 371 | 382 | const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 |
| ... | ... | @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { |
| 380 | 391 | { |
| 381 | 392 | var ptr: [*]align(8) [3]u8 = undefined; |
| 382 | 393 | var x: usize = 1; |
| 394 | _ = .{ &ptr, &x }; | |
| 383 | 395 | |
| 384 | 396 | const ptr1 = ptr + 17; // 3 * 17 = 51 |
| 385 | 397 | try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); |
| ... | ... | @@ -467,8 +479,8 @@ test "array slicing to slice" { |
| 467 | 479 | const S = struct { |
| 468 | 480 | fn doTheTest() !void { |
| 469 | 481 | var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; |
| 470 | var sub: *[2]i32 = str[1..3]; | |
| 471 | var slice: []i32 = sub; // used to cause failures | |
| 482 | const sub: *[2]i32 = str[1..3]; | |
| 483 | const slice: []i32 = sub; // used to cause failures | |
| 472 | 484 | try testing.expect(slice.len == 2); |
| 473 | 485 | try testing.expect(slice[0] == 2); |
| 474 | 486 | } |
| ... | ... | @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { |
| 495 | 507 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 496 | 508 | |
| 497 | 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 | 512 | try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); |
| 500 | 513 | } |
| 501 | 514 | |
| ... | ... | @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { |
| 527 | 540 | test "result type preserved through multiple references" { |
| 528 | 541 | const S = struct { x: u32 }; |
| 529 | 542 | var my_u64: u64 = 12345; |
| 543 | _ = &my_u64; | |
| 530 | 544 | const foo: *const *const *const S = &&&.{ |
| 531 | 545 | .x = @intCast(my_u64), |
| 532 | 546 | }; |
test/behavior/popcount.zig+10| ... | ... | @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { |
| 26 | 26 | |
| 27 | 27 | { |
| 28 | 28 | var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; |
| 29 | _ = &x; | |
| 29 | 30 | try expect(@popCount(x) == 24); |
| 30 | 31 | } |
| 31 | 32 | |
| ... | ... | @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { |
| 35 | 36 | fn testPopCountIntegers() !void { |
| 36 | 37 | { |
| 37 | 38 | var x: u32 = 0xffffffff; |
| 39 | _ = &x; | |
| 38 | 40 | try expect(@popCount(x) == 32); |
| 39 | 41 | } |
| 40 | 42 | { |
| 41 | 43 | var x: u5 = 0x1f; |
| 44 | _ = &x; | |
| 42 | 45 | try expect(@popCount(x) == 5); |
| 43 | 46 | } |
| 44 | 47 | { |
| 45 | 48 | var x: u32 = 0xaa; |
| 49 | _ = &x; | |
| 46 | 50 | try expect(@popCount(x) == 4); |
| 47 | 51 | } |
| 48 | 52 | { |
| 49 | 53 | var x: u32 = 0xaaaaaaaa; |
| 54 | _ = &x; | |
| 50 | 55 | try expect(@popCount(x) == 16); |
| 51 | 56 | } |
| 52 | 57 | { |
| 53 | 58 | var x: u32 = 0xaaaaaaaa; |
| 59 | _ = &x; | |
| 54 | 60 | try expect(@popCount(x) == 16); |
| 55 | 61 | } |
| 56 | 62 | { |
| 57 | 63 | var x: i16 = -1; |
| 64 | _ = &x; | |
| 58 | 65 | try expect(@popCount(x) == 16); |
| 59 | 66 | } |
| 60 | 67 | { |
| 61 | 68 | var x: i8 = -120; |
| 69 | _ = &x; | |
| 62 | 70 | try expect(@popCount(x) == 2); |
| 63 | 71 | } |
| 64 | 72 | comptime { |
| ... | ... | @@ -81,12 +89,14 @@ test "@popCount vectors" { |
| 81 | 89 | fn testPopCountVectors() !void { |
| 82 | 90 | { |
| 83 | 91 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; |
| 92 | _ = &x; | |
| 84 | 93 | const expected = [1]u6{32} ** 8; |
| 85 | 94 | const result: [8]u6 = @popCount(x); |
| 86 | 95 | try expect(std.mem.eql(u6, &expected, &result)); |
| 87 | 96 | } |
| 88 | 97 | { |
| 89 | 98 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; |
| 99 | _ = &x; | |
| 90 | 100 | const expected = [1]u5{16} ** 8; |
| 91 | 101 | const result: [8]u5 = @popCount(x); |
| 92 | 102 | try expect(std.mem.eql(u5, &expected, &result)); |
test/behavior/prefetch.zig+1| ... | ... | @@ -6,6 +6,7 @@ test "@prefetch()" { |
| 6 | 6 | |
| 7 | 7 | var a: [2]u32 = .{ 42, 42 }; |
| 8 | 8 | var a_len = a.len; |
| 9 | _ = &a_len; | |
| 9 | 10 | |
| 10 | 11 | @prefetch(&a, .{}); |
| 11 | 12 |
test/behavior/ptrcast.zig+14-14| ... | ... | @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { |
| 71 | 71 | c: u8, |
| 72 | 72 | }; |
| 73 | 73 | |
| 74 | var ptr = @as(*const S, @ptrCast(&bytes)); | |
| 75 | var val = ptr.c; | |
| 74 | const ptr: *const S = @ptrCast(&bytes); | |
| 75 | const val = ptr.c; | |
| 76 | 76 | try expect(val == 5); |
| 77 | 77 | } |
| 78 | 78 | |
| ... | ... | @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { |
| 95 | 95 | a: u32 align(2), |
| 96 | 96 | c: u8, |
| 97 | 97 | }; |
| 98 | var ptr = @as(*const S2, @ptrCast(&bytes)); | |
| 99 | var val = ptr.c; | |
| 98 | const ptr: *const S2 = @ptrCast(&bytes); | |
| 99 | const val = ptr.c; | |
| 100 | 100 | try expect(val == 5); |
| 101 | 101 | } |
| 102 | 102 | |
| ... | ... | @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { |
| 121 | 121 | a2: u16, |
| 122 | 122 | c: u8, |
| 123 | 123 | }; |
| 124 | var ptr = @as(*const S2, @ptrCast(&bytes)); | |
| 125 | var val = ptr.c; | |
| 124 | const ptr: *const S2 = @ptrCast(&bytes); | |
| 125 | const val = ptr.c; | |
| 126 | 126 | try expect(val == 5); |
| 127 | 127 | } |
| 128 | 128 | |
| ... | ... | @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { |
| 138 | 138 | c: u8, |
| 139 | 139 | }; |
| 140 | 140 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); |
| 141 | var val = &ptr.c; | |
| 141 | const val = &ptr.c; | |
| 142 | 142 | try expect(val.* == 5); |
| 143 | 143 | |
| 144 | 144 | // Test lowering an elem ptr |
| 145 | 145 | comptime var src_value = S{ .a = 15, .c = 5 }; |
| 146 | 146 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); |
| 147 | var val2 = &ptr2[4]; | |
| 147 | const val2 = &ptr2[4]; | |
| 148 | 148 | try expect(val2.* == 5); |
| 149 | 149 | } |
| 150 | 150 | |
| ... | ... | @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { |
| 160 | 160 | c: u8, |
| 161 | 161 | }; |
| 162 | 162 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); |
| 163 | var val = &ptr.c; | |
| 163 | const val = &ptr.c; | |
| 164 | 164 | try expect(val.* == 5); |
| 165 | 165 | |
| 166 | 166 | // Test lowering an elem ptr |
| 167 | 167 | comptime var src_value = S{ .a = 15, .c = 5 }; |
| 168 | 168 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); |
| 169 | var val2 = &ptr2[4]; | |
| 169 | const val2 = &ptr2[4]; | |
| 170 | 170 | try expect(val2.* == 5); |
| 171 | 171 | } |
| 172 | 172 | |
| ... | ... | @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { |
| 233 | 233 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 234 | 234 | |
| 235 | 235 | var buf: [4]u8 = "aoeu".*; |
| 236 | var x: ?[*]u8 = &buf; | |
| 237 | var y: ?*anyopaque = x; | |
| 238 | var z = @as(*[4]u8, @ptrCast(y)); | |
| 236 | const x: ?[*]u8 = &buf; | |
| 237 | const y: ?*anyopaque = x; | |
| 238 | const z: *[4]u8 = @ptrCast(y); | |
| 239 | 239 | try expect(std.mem.eql(u8, z, "aoeu")); |
| 240 | 240 | } |
| 241 | 241 | |
| ... | ... | @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { |
| 276 | 276 | } |
| 277 | 277 | }; |
| 278 | 278 | comptime { |
| 279 | var x = S.transmute([]u8, i32, undefined); | |
| 279 | const x = S.transmute([]u8, i32, undefined); | |
| 280 | 280 | _ = x; |
| 281 | 281 | } |
| 282 | 282 | } |
test/behavior/ptrfromint.zig+1| ... | ... | @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { |
| 9 | 9 | |
| 10 | 10 | fn addressToFunction() void { |
| 11 | 11 | var addr: usize = 0xdeadbee0; |
| 12 | _ = &addr; | |
| 12 | 13 | _ = @as(*const fn () void, @ptrFromInt(addr)); |
| 13 | 14 | } |
| 14 | 15 |
test/behavior/saturating_arithmetic.zig+2| ... | ... | @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { |
| 246 | 246 | |
| 247 | 247 | const lhs_const: u8 = 1; |
| 248 | 248 | var lhs_var: u8 = 1; |
| 249 | _ = &lhs_var; | |
| 249 | 250 | |
| 250 | 251 | const rhs_const: usize = 8; |
| 251 | 252 | var rhs_var: usize = 8; |
| 253 | _ = &rhs_var; | |
| 252 | 254 | |
| 253 | 255 | try expect((lhs_const <<| 8) == 255); |
| 254 | 256 | try expect((lhs_const <<| rhs_const) == 255); |
test/behavior/select.zig+8-4| ... | ... | @@ -19,7 +19,8 @@ fn selectVectors() !void { |
| 19 | 19 | var a = @Vector(4, bool){ true, false, true, false }; |
| 20 | 20 | var b = @Vector(4, i32){ -1, 4, 999, -31 }; |
| 21 | 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 | 24 | try expect(abc[0] == -1); |
| 24 | 25 | try expect(abc[1] == 1); |
| 25 | 26 | try expect(abc[2] == 999); |
| ... | ... | @@ -28,7 +29,8 @@ fn selectVectors() !void { |
| 28 | 29 | var x = @Vector(4, bool){ false, false, false, true }; |
| 29 | 30 | var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; |
| 30 | 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 | 34 | try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); |
| 33 | 35 | } |
| 34 | 36 | |
| ... | ... | @@ -48,7 +50,8 @@ fn selectArrays() !void { |
| 48 | 50 | var a = [4]bool{ false, true, false, true }; |
| 49 | 51 | var b = [4]usize{ 0, 1, 2, 3 }; |
| 50 | 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 | 55 | try expect(abc[0] == 4); |
| 53 | 56 | try expect(abc[1] == 1); |
| 54 | 57 | try expect(abc[2] == 6); |
| ... | ... | @@ -57,6 +60,7 @@ fn selectArrays() !void { |
| 57 | 60 | var x = [4]bool{ false, false, false, true }; |
| 58 | 61 | var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; |
| 59 | 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 | 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 | 13 | const S = struct { |
| 14 | 14 | fn doTheTest() !void { |
| 15 | 15 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 16 | _ = &v; | |
| 16 | 17 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 18 | _ = &x; | |
| 17 | 19 | const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; |
| 18 | 20 | var res = @shuffle(i32, v, x, mask); |
| 19 | 21 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); |
| ... | ... | @@ -29,12 +31,14 @@ test "@shuffle int" { |
| 29 | 31 | |
| 30 | 32 | // Upcasting of b |
| 31 | 33 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; |
| 34 | _ = &v2; | |
| 32 | 35 | const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; |
| 33 | 36 | res = @shuffle(i32, x, v2, mask3); |
| 34 | 37 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); |
| 35 | 38 | |
| 36 | 39 | // Upcasting of a |
| 37 | 40 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; |
| 41 | _ = &v3; | |
| 38 | 42 | const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; |
| 39 | 43 | res = @shuffle(i32, v3, x, mask4); |
| 40 | 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 | 59 | const S = struct { |
| 56 | 60 | fn doTheTest() !void { |
| 57 | 61 | var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; |
| 62 | _ = &x; | |
| 58 | 63 | var v: @Vector(2, bool) = [2]bool{ true, false }; |
| 64 | _ = &v; | |
| 59 | 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 | 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 | 87 | const S = struct { |
| 82 | 88 | fn doTheTest() !void { |
| 83 | 89 | var x: @Vector(3, bool) = [3]bool{ false, true, false }; |
| 90 | _ = &x; | |
| 84 | 91 | var v: @Vector(2, bool) = [2]bool{ true, false }; |
| 92 | _ = &v; | |
| 85 | 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 | 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 | 22 | var var_1: u32 = undefined; |
| 23 | 23 | var var_2: u8 = undefined; |
| 24 | 24 | var var_3: u64 = undefined; |
| 25 | _ = .{ &var_1, &var_2, &var_3 }; | |
| 25 | 26 | try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); |
| 26 | 27 | } |
| 27 | 28 | { |
| 28 | 29 | var var_1: f16 = undefined; |
| 29 | 30 | var var_2: f32 = undefined; |
| 30 | 31 | var var_3: f64 = undefined; |
| 32 | _ = .{ &var_1, &var_2, &var_3 }; | |
| 31 | 33 | try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); |
| 32 | 34 | } |
| 33 | 35 | { |
| 34 | 36 | var var_1: u16 = undefined; |
| 37 | _ = &var_1; | |
| 35 | 38 | try comptime expect(@TypeOf(var_1, 0xffff) == u16); |
| 36 | 39 | } |
| 37 | 40 | { |
| 38 | 41 | var var_1: f32 = undefined; |
| 42 | _ = &var_1; | |
| 39 | 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 | 273 | |
| 270 | 274 | { |
| 271 | 275 | var y: i8 = 2; |
| 276 | _ = &y; | |
| 272 | 277 | const i: [2]i8 = [_]i8{ 1, y }; |
| 273 | 278 | const T = struct { |
| 274 | 279 | a: @TypeOf(i) = undefined, // causes crash |
| ... | ... | @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { |
| 279 | 284 | } |
| 280 | 285 | { |
| 281 | 286 | var y: i8 = 2; |
| 287 | _ = &y; | |
| 282 | 288 | const i = .{ 1, y }; |
| 283 | 289 | const T = struct { |
| 284 | 290 | b: @TypeOf(i[1]) = undefined, |
test/behavior/slice.zig+44-32| ... | ... | @@ -23,7 +23,7 @@ comptime { |
| 23 | 23 | }; |
| 24 | 24 | const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; |
| 25 | 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 | 27 | if (pos != 1) @compileError("bad pos"); |
| 28 | 28 | } |
| 29 | 29 | |
| ... | ... | @@ -36,13 +36,14 @@ test "slicing" { |
| 36 | 36 | |
| 37 | 37 | var slice = array[5..10]; |
| 38 | 38 | |
| 39 | if (slice.len != 5) unreachable; | |
| 39 | try expect(slice.len == 5); | |
| 40 | 40 | |
| 41 | 41 | const ptr = &slice[0]; |
| 42 | if (ptr.* != 1234) unreachable; | |
| 42 | try expect(ptr.* == 1234); | |
| 43 | 43 | |
| 44 | 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 | } |
| 47 | 48 | |
| 48 | 49 | test "const slice" { |
| ... | ... | @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { |
| 79 | 80 | const S = struct { |
| 80 | 81 | fn doTheTest() !void { |
| 81 | 82 | var slice: [:0]const u8 = "hello"; |
| 82 | ||
| 83 | _ = &slice; | |
| 83 | 84 | try expect(slice.len == 5); |
| 84 | 85 | try expect(slice[5] == 0); |
| 85 | 86 | } |
| ... | ... | @@ -208,6 +209,7 @@ test "slice string literal has correct type" { |
| 208 | 209 | try expect(@TypeOf(array[0..]) == *const [4]i32); |
| 209 | 210 | } |
| 210 | 211 | var runtime_zero: usize = 0; |
| 212 | _ = &runtime_zero; | |
| 211 | 213 | try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); |
| 212 | 214 | const array = [_]i32{ 1, 2, 3, 4 }; |
| 213 | 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 | 221 | const E = struct { |
| 220 | 222 | entries: []u32, |
| 221 | 223 | }; |
| 222 | var foo = E{ .entries = &[_]u32{} }; | |
| 224 | var foo: E = .{ .entries = &[_]u32{} }; | |
| 225 | _ = &foo; | |
| 223 | 226 | try expect(foo.entries.len == 0); |
| 224 | 227 | } |
| 225 | 228 | |
| ... | ... | @@ -242,7 +245,8 @@ test "C pointer" { |
| 242 | 245 | |
| 243 | 246 | var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; |
| 244 | 247 | var len: u32 = 10; |
| 245 | var slice = buf[0..len]; | |
| 248 | _ = &len; | |
| 249 | const slice = buf[0..len]; | |
| 246 | 250 | try expect(mem.eql(u8, "kjdhfkjdhf", slice)); |
| 247 | 251 | } |
| 248 | 252 | |
| ... | ... | @@ -255,6 +259,7 @@ test "C pointer slice access" { |
| 255 | 259 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); |
| 256 | 260 | |
| 257 | 261 | var runtime_zero: usize = 0; |
| 262 | _ = &runtime_zero; | |
| 258 | 263 | try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); |
| 259 | 264 | try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); |
| 260 | 265 | |
| ... | ... | @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { |
| 306 | 311 | _ = ptr; |
| 307 | 312 | |
| 308 | 313 | var runtime_len: usize = 3; |
| 314 | _ = &runtime_len; | |
| 309 | 315 | const ptr2 = buf[0..runtime_len :0]; |
| 310 | 316 | // ptr2 is a null-terminated slice |
| 311 | 317 | try comptime expect(@TypeOf(ptr2) == [:0]u8); |
| 312 | 318 | try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); |
| 313 | 319 | var runtime_zero: usize = 0; |
| 320 | _ = &runtime_zero; | |
| 314 | 321 | try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); |
| 315 | 322 | } |
| 316 | 323 | |
| ... | ... | @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { |
| 338 | 345 | const S = struct { |
| 339 | 346 | fn doTheTest() !void { |
| 340 | 347 | var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 341 | var slice: []align(@alignOf(u16)) u8 = &array; | |
| 342 | var ptr = @as(*u16, @ptrCast(slice)); | |
| 348 | const slice: []align(@alignOf(u16)) u8 = &array; | |
| 349 | const ptr: *u16 = @ptrCast(slice); | |
| 343 | 350 | try expect(ptr.* == 65535); |
| 344 | 351 | } |
| 345 | 352 | }; |
| ... | ... | @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { |
| 357 | 364 | |
| 358 | 365 | fn testPointer() !void { |
| 359 | 366 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 360 | var pointer: [*]u8 = &array; | |
| 361 | var slice = pointer[1..]; | |
| 367 | const pointer: [*]u8 = &array; | |
| 368 | const slice = pointer[1..]; | |
| 362 | 369 | try comptime expect(@TypeOf(slice) == [*]u8); |
| 363 | 370 | try expect(slice[0] == 2); |
| 364 | 371 | try expect(slice[1] == 3); |
| ... | ... | @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { |
| 366 | 373 | |
| 367 | 374 | fn testPointerZ() !void { |
| 368 | 375 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 369 | var pointer: [*:0]u8 = &array; | |
| 376 | const pointer: [*:0]u8 = &array; | |
| 370 | 377 | |
| 371 | 378 | try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); |
| 372 | 379 | try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); |
| 373 | 380 | try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); |
| 374 | 381 | |
| 375 | var slice = pointer[1..]; | |
| 382 | const slice = pointer[1..]; | |
| 376 | 383 | try comptime expect(@TypeOf(slice) == [*:0]u8); |
| 377 | 384 | try expect(slice[0] == 2); |
| 378 | 385 | try expect(slice[1] == 3); |
| ... | ... | @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 413 | 420 | |
| 414 | 421 | fn testArray() !void { |
| 415 | 422 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 416 | var slice = array[1..3]; | |
| 423 | const slice = array[1..3]; | |
| 417 | 424 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 418 | 425 | try expect(slice[0] == 2); |
| 419 | 426 | try expect(slice[1] == 3); |
| ... | ... | @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { |
| 430 | 437 | fn testArray0() !void { |
| 431 | 438 | { |
| 432 | 439 | var array = [0]u8{}; |
| 433 | var slice = array[0..0]; | |
| 440 | const slice = array[0..0]; | |
| 434 | 441 | try comptime expect(@TypeOf(slice) == *[0]u8); |
| 435 | 442 | } |
| 436 | 443 | { |
| 437 | 444 | var array = [0:0]u8{}; |
| 438 | var slice = array[0..0]; | |
| 445 | const slice = array[0..0]; | |
| 439 | 446 | try comptime expect(@TypeOf(slice) == *[0:0]u8); |
| 440 | 447 | try expect(slice[0] == 0); |
| 441 | 448 | } |
| ... | ... | @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 443 | 450 | |
| 444 | 451 | fn testArrayAlign() !void { |
| 445 | 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 | 454 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 448 | 455 | try expect(slice[0] == 5); |
| 449 | 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 | 459 | fn testPointer() !void { |
| 453 | 460 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 454 | 461 | var pointer: [*]u8 = &array; |
| 455 | var slice = pointer[1..3]; | |
| 462 | const slice = pointer[1..3]; | |
| 456 | 463 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 457 | 464 | try expect(slice[0] == 2); |
| 458 | 465 | try expect(slice[1] == 3); |
| ... | ... | @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 467 | 474 | |
| 468 | 475 | fn testPointer0() !void { |
| 469 | 476 | var pointer: [*]const u0 = &[1]u0{0}; |
| 470 | var slice = pointer[0..1]; | |
| 477 | const slice = pointer[0..1]; | |
| 471 | 478 | try comptime expect(@TypeOf(slice) == *const [1]u0); |
| 472 | 479 | try expect(slice[0] == 0); |
| 473 | 480 | } |
| ... | ... | @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 475 | 482 | fn testPointerAlign() !void { |
| 476 | 483 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 477 | 484 | var pointer: [*]align(4) u8 = &array; |
| 478 | var slice = pointer[4..5]; | |
| 485 | const slice = pointer[4..5]; | |
| 479 | 486 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 480 | 487 | try expect(slice[0] == 5); |
| 481 | 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 | 491 | fn testSlice() !void { |
| 485 | 492 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 486 | 493 | var src_slice: []u8 = &array; |
| 487 | var slice = src_slice[1..3]; | |
| 494 | const slice = src_slice[1..3]; | |
| 488 | 495 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 489 | 496 | try expect(slice[0] == 2); |
| 490 | 497 | try expect(slice[1] == 3); |
| ... | ... | @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 513 | 520 | fn testSliceAlign() !void { |
| 514 | 521 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 515 | 522 | var src_slice: []align(4) u8 = &array; |
| 516 | var slice = src_slice[4..5]; | |
| 523 | const slice = src_slice[4..5]; | |
| 517 | 524 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 518 | 525 | try expect(slice[0] == 5); |
| 519 | 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 | 623 | { |
| 617 | 624 | var array = [0]u8{}; |
| 618 | 625 | var src_slice: []u8 = &array; |
| 619 | var slice = src_slice[0..0]; | |
| 626 | const slice = src_slice[0..0]; | |
| 620 | 627 | try expect(@TypeOf(slice) == *[0]u8); |
| 621 | 628 | } |
| 622 | 629 | { |
| 623 | 630 | var array = [0:0]u8{}; |
| 624 | 631 | var src_slice: [:0]u8 = &array; |
| 625 | var slice = src_slice[0..0]; | |
| 632 | const slice = src_slice[0..0]; | |
| 626 | 633 | try expect(@TypeOf(slice) == *[0:0]u8); |
| 627 | 634 | } |
| 628 | 635 | } |
| ... | ... | @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { |
| 630 | 637 | { |
| 631 | 638 | var array = [0]u8{}; |
| 632 | 639 | var src_slice: []u8 = &array; |
| 633 | var slice = src_slice[0..0]; | |
| 640 | const slice = src_slice[0..0]; | |
| 634 | 641 | try comptime expect(@TypeOf(slice) == *[0]u8); |
| 635 | 642 | } |
| 636 | 643 | { |
| 637 | 644 | var array = [0:0]u8{}; |
| 638 | 645 | var src_slice: [:0]u8 = &array; |
| 639 | var slice = src_slice[0..0]; | |
| 646 | const slice = src_slice[0..0]; | |
| 640 | 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 | 662 | |
| 656 | 663 | fn doTheTest() !void { |
| 657 | 664 | var x1: u8 = 42; |
| 665 | _ = &x1; | |
| 658 | 666 | const t1 = &.{ x1, 56, 54 }; |
| 659 | var slice1: []const u8 = t1; | |
| 667 | const slice1: []const u8 = t1; | |
| 660 | 668 | try expect(slice1.len == 3); |
| 661 | 669 | try expect(slice1[0] == 42); |
| 662 | 670 | try expect(slice1[1] == 56); |
| 663 | 671 | try expect(slice1[2] == 54); |
| 664 | 672 | |
| 665 | 673 | var x2: []const u8 = "hello"; |
| 674 | _ = &x2; | |
| 666 | 675 | const t2 = &.{ x2, ", ", "world!" }; |
| 667 | 676 | // @compileLog(@TypeOf(t2)); |
| 668 | var slice2: []const []const u8 = t2; | |
| 677 | const slice2: []const []const u8 = t2; | |
| 669 | 678 | try expect(slice2.len == 3); |
| 670 | 679 | try expect(mem.eql(u8, slice2[0], "hello")); |
| 671 | 680 | try expect(mem.eql(u8, slice2[1], ", ")); |
| ... | ... | @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { |
| 680 | 689 | comptime { |
| 681 | 690 | var a: []const u8 = "aoeu"; |
| 682 | 691 | var b: []const u8 = "asdf"; |
| 692 | _ = .{ &a, &b }; | |
| 683 | 693 | const c = a ++ b; |
| 684 | 694 | try expect(std.mem.eql(u8, c, "aoeuasdf")); |
| 685 | 695 | try expect(@TypeOf(c) == *const [8]u8); |
| ... | ... | @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { |
| 689 | 699 | test "array mult of slice gives ptr to array" { |
| 690 | 700 | comptime { |
| 691 | 701 | var a: []const u8 = "aoeu"; |
| 702 | _ = &a; | |
| 692 | 703 | const c = a ** 2; |
| 693 | 704 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); |
| 694 | 705 | try expect(@TypeOf(c) == *const [8]u8); |
| ... | ... | @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { |
| 736 | 747 | const S = struct { |
| 737 | 748 | fn do() !void { |
| 738 | 749 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 739 | var slice = array[4..5]; | |
| 750 | const slice = array[4..5]; | |
| 740 | 751 | try expect(slice.len == 1); |
| 741 | 752 | try expect(slice[0] == 0); |
| 742 | 753 | try expect(@TypeOf(slice) == *[1]u8); |
| ... | ... | @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { |
| 754 | 765 | const S = struct { |
| 755 | 766 | fn do() !void { |
| 756 | 767 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 757 | var src_slice: [:0]u8 = &array; | |
| 758 | var slice = src_slice[4..5]; | |
| 768 | const src_slice: [:0]u8 = &array; | |
| 769 | const slice = src_slice[4..5]; | |
| 759 | 770 | try expect(slice.len == 1); |
| 760 | 771 | try expect(slice[0] == 0); |
| 761 | 772 | try expect(@TypeOf(slice) == *[1]u8); |
| ... | ... | @@ -820,6 +831,7 @@ test "global slice field access" { |
| 820 | 831 | |
| 821 | 832 | test "slice of void" { |
| 822 | 833 | var n: usize = 10; |
| 834 | _ = &n; | |
| 823 | 835 | var arr: [12]void = undefined; |
| 824 | 836 | const slice = @as([]void, &arr)[0..n]; |
| 825 | 837 | try expect(slice.len == n); |
| ... | ... | @@ -827,7 +839,7 @@ test "slice of void" { |
| 827 | 839 | |
| 828 | 840 | test "slice with dereferenced value" { |
| 829 | 841 | var a: usize = 0; |
| 830 | var idx: *usize = &a; | |
| 842 | const idx: *usize = &a; | |
| 831 | 843 | _ = blk: { |
| 832 | 844 | var array = [_]u8{}; |
| 833 | 845 | break :blk array[idx.*..]; |
test/behavior/struct.zig+44-21| ... | ... | @@ -254,7 +254,8 @@ test "struct field init with catch" { |
| 254 | 254 | const S = struct { |
| 255 | 255 | fn doTheTest() !void { |
| 256 | 256 | var x: anyerror!isize = 1; |
| 257 | var req = Foo{ | |
| 257 | _ = &x; | |
| 258 | const req = Foo{ | |
| 258 | 259 | .field = x catch undefined, |
| 259 | 260 | }; |
| 260 | 261 | try expect(req.field == 1); |
| ... | ... | @@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" { |
| 505 | 506 | var all: u64 = 0x7765443322221111; |
| 506 | 507 | var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; |
| 507 | 508 | @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); |
| 508 | var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; | |
| 509 | const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; | |
| 509 | 510 | |
| 510 | 511 | try expect(bitfields.f1 == 0x1111); |
| 511 | 512 | try expect(bitfields.f2 == 0x2222); |
| ... | ... | @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { |
| 545 | 546 | y: void, |
| 546 | 547 | }; |
| 547 | 548 | var x: S = undefined; |
| 548 | _ = x; | |
| 549 | _ = &x; | |
| 549 | 550 | } |
| 550 | 551 | |
| 551 | 552 | test "packed struct with non-ABI-aligned field" { |
| ... | ... | @@ -624,6 +625,7 @@ test "default struct initialization fields" { |
| 624 | 625 | .b = 5, |
| 625 | 626 | }; |
| 626 | 627 | var five: i32 = 5; |
| 628 | _ = &five; | |
| 627 | 629 | const y = S{ |
| 628 | 630 | .b = five, |
| 629 | 631 | }; |
| ... | ... | @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { |
| 714 | 716 | }; |
| 715 | 717 | |
| 716 | 718 | var s = S{ .a = 2, .b = 0 }; |
| 717 | var b_ptr = &s.b; | |
| 719 | const b_ptr = &s.b; | |
| 718 | 720 | try expect(s.b == 0); |
| 719 | 721 | b_ptr.* = 2; |
| 720 | 722 | try expect(s.b == 2); |
| ... | ... | @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { |
| 727 | 729 | f0: u0, |
| 728 | 730 | }; |
| 729 | 731 | var s = S{ .f0 = 0 }; |
| 732 | _ = &s; | |
| 730 | 733 | try comptime expect(s.f0 == 0); |
| 731 | 734 | } |
| 732 | 735 | |
| ... | ... | @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { |
| 788 | 791 | |
| 789 | 792 | const S = struct { |
| 790 | 793 | fn entry() !void { |
| 791 | var x = makeBar(10); | |
| 794 | const x = makeBar(10); | |
| 792 | 795 | try expect(@as(i32, 10) == x.handle); |
| 793 | 796 | } |
| 794 | 797 | |
| ... | ... | @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { |
| 827 | 830 | var s = &sx; |
| 828 | 831 | try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); |
| 829 | 832 | var v2 = U{ .Num = 123 }; |
| 833 | _ = &v2; | |
| 830 | 834 | s.f2 = v2; |
| 831 | 835 | try expect(s.f2.Num == 123); |
| 832 | 836 | } |
| ... | ... | @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { |
| 852 | 856 | |
| 853 | 857 | var p: S.P = undefined; |
| 854 | 858 | p.b = 29; |
| 855 | var loaded = S.genericReadPackedField(&p.b); | |
| 859 | const loaded = S.genericReadPackedField(&p.b); | |
| 856 | 860 | try expect(loaded == 29); |
| 857 | 861 | } |
| 858 | 862 | |
| ... | ... | @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { |
| 871 | 875 | .x = 1, |
| 872 | 876 | .y = 2, |
| 873 | 877 | }; |
| 878 | _ = &p; | |
| 874 | 879 | try expect(p.x == 1); |
| 875 | 880 | try expect(p.y == 2); |
| 876 | 881 | } |
| ... | ... | @@ -920,6 +925,7 @@ test "fully anonymous list literal" { |
| 920 | 925 | |
| 921 | 926 | test "tuple assigned to variable" { |
| 922 | 927 | var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; |
| 928 | _ = &vec; | |
| 923 | 929 | try expect(vec.@"0" == 22); |
| 924 | 930 | try expect(vec.@"1" == 55); |
| 925 | 931 | try expect(vec.@"2" == 99); |
| ... | ... | @@ -940,6 +946,7 @@ test "comptime struct field" { |
| 940 | 946 | comptime std.debug.assert(@sizeOf(T) == 4); |
| 941 | 947 | |
| 942 | 948 | var foo: T = undefined; |
| 949 | _ = &foo; | |
| 943 | 950 | try comptime expect(foo.b == 1234); |
| 944 | 951 | } |
| 945 | 952 | |
| ... | ... | @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { |
| 950 | 957 | |
| 951 | 958 | const S = struct { |
| 952 | 959 | fn doTheTest() !void { |
| 953 | var x = .{foo()}; | |
| 960 | const x = .{foo()}; | |
| 954 | 961 | try expectEqualSlices(u8, x[0], "hi"); |
| 955 | 962 | } |
| 956 | 963 | fn foo() []const u8 { |
| ... | ... | @@ -977,6 +984,7 @@ test "struct with union field" { |
| 977 | 984 | var True = Value{ |
| 978 | 985 | .kind = .{ .Bool = true }, |
| 979 | 986 | }; |
| 987 | _ = &True; | |
| 980 | 988 | try expect(@as(u32, 2) == True.ref); |
| 981 | 989 | try expect(True.kind.Bool); |
| 982 | 990 | } |
| ... | ... | @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { |
| 996 | 1004 | }; |
| 997 | 1005 | |
| 998 | 1006 | var s: S = undefined; |
| 1007 | _ = &s; | |
| 999 | 1008 | try expectEqual(@as(usize, 0), s.zero_length.len); |
| 1000 | 1009 | } |
| 1001 | 1010 | |
| ... | ... | @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { |
| 1019 | 1028 | |
| 1020 | 1029 | fn doTheTest() !void { |
| 1021 | 1030 | var y: u32 = 42; |
| 1031 | _ = &y; | |
| 1022 | 1032 | const t0 = .{ .A = 123, .B = "foo", .C = {} }; |
| 1023 | 1033 | const t1 = .{ .A = y, .B = "foo", .C = {} }; |
| 1024 | 1034 | const y0: S2 = t0; |
| 1025 | var y1: S2 = t1; | |
| 1035 | const y1: S2 = t1; | |
| 1026 | 1036 | try expect(y0.A == 123); |
| 1027 | 1037 | try expect(std.mem.eql(u8, y0.B, "foo")); |
| 1028 | 1038 | try expect(y0.C == {}); |
| ... | ... | @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { |
| 1057 | 1067 | |
| 1058 | 1068 | fn doTheTest() !void { |
| 1059 | 1069 | var y: u32 = 42; |
| 1070 | _ = &y; | |
| 1060 | 1071 | const t0 = &.{ .A = 123, .B = "foo", .C = {} }; |
| 1061 | 1072 | const t1 = &.{ .A = y, .B = "foo", .C = {} }; |
| 1062 | 1073 | const y0: *const S2 = t0; |
| 1063 | var y1: *const S2 = t1; | |
| 1074 | const y1: *const S2 = t1; | |
| 1064 | 1075 | try expect(y0.A == 123); |
| 1065 | 1076 | try expect(std.mem.eql(u8, y0.B, "foo")); |
| 1066 | 1077 | try expect(y0.C == {}); |
| ... | ... | @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { |
| 1161 | 1172 | } |
| 1162 | 1173 | |
| 1163 | 1174 | fn doTheTest() !void { |
| 1164 | var a = try (try foo()).?; | |
| 1165 | var b = try bar().?; | |
| 1175 | const a = try (try foo()).?; | |
| 1176 | const b = try bar().?; | |
| 1166 | 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 | 1238 | } |
| 1228 | 1239 | |
| 1229 | 1240 | fn doTheTest() !void { |
| 1230 | var a = try (try foo()).?; | |
| 1231 | var b = try bar().?; | |
| 1241 | const a = try (try foo()).?; | |
| 1242 | const b = try bar().?; | |
| 1232 | 1243 | try expect(a.a + b[1] == 3); |
| 1233 | 1244 | } |
| 1234 | 1245 | }; |
| ... | ... | @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { |
| 1243 | 1254 | |
| 1244 | 1255 | const S = struct { x: i32 = 1234 }; |
| 1245 | 1256 | var s: S = .{}; |
| 1257 | _ = &s; | |
| 1246 | 1258 | try expect(s.x == 1234); |
| 1247 | 1259 | } |
| 1248 | 1260 | |
| ... | ... | @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { |
| 1301 | 1313 | fn doTheTest() !void { |
| 1302 | 1314 | const S = packed struct { a: u30 }; |
| 1303 | 1315 | var s1: S = .{ .a = 1 }; |
| 1304 | var s2 = &s1; | |
| 1316 | const s2 = &s1; | |
| 1305 | 1317 | try expect(s2.a == 1); |
| 1306 | 1318 | var s3: S = undefined; |
| 1307 | var s4 = &s3; | |
| 1319 | const s4 = &s3; | |
| 1308 | 1320 | _ = s4; |
| 1309 | 1321 | } |
| 1310 | 1322 | }; |
| ... | ... | @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { |
| 1343 | 1355 | }; |
| 1344 | 1356 | }; |
| 1345 | 1357 | var s: namespace.S = .{ .blah = 1234 }; |
| 1358 | _ = &s; | |
| 1346 | 1359 | try expect(s.size == 4); |
| 1347 | 1360 | } |
| 1348 | 1361 | |
| ... | ... | @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { |
| 1362 | 1375 | data: U align(4), |
| 1363 | 1376 | }; |
| 1364 | 1377 | var runtime: usize = 1234; |
| 1378 | _ = &runtime; | |
| 1365 | 1379 | const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; |
| 1366 | 1380 | const array = @as(*const [12]u8, @ptrCast(ptr)); |
| 1367 | 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 | 1523 | } |
| 1510 | 1524 | }; |
| 1511 | 1525 | var a = A.f(); |
| 1526 | _ = &a; | |
| 1512 | 1527 | try expect(a.f == A.f); |
| 1513 | 1528 | } |
| 1514 | 1529 | |
| ... | ... | @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { |
| 1538 | 1553 | a: ?struct { b: u32 }, |
| 1539 | 1554 | }; |
| 1540 | 1555 | var a: u32 = 0; |
| 1541 | var b = S{ | |
| 1556 | _ = &a; | |
| 1557 | const b = S{ | |
| 1542 | 1558 | .a = .{ .b = a }, |
| 1543 | 1559 | }; |
| 1544 | 1560 | try expect(b.a.?.b == a); |
| ... | ... | @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { |
| 1550 | 1566 | const MyStruct = struct { x: u32 }; |
| 1551 | 1567 | const b: u32 = 5; |
| 1552 | 1568 | var i: u32 = 1; |
| 1553 | var my_var = if (i < 5) | |
| 1569 | _ = &i; | |
| 1570 | const my_var = if (i < 5) | |
| 1554 | 1571 | MyStruct{ |
| 1555 | 1572 | .x = 1 + if (i > 0) b else 0, |
| 1556 | 1573 | } |
| ... | ... | @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { |
| 1599 | 1616 | var things = struct { |
| 1600 | 1617 | comptime foo: i8 = 1, |
| 1601 | 1618 | }{}; |
| 1602 | ||
| 1619 | _ = &things; | |
| 1603 | 1620 | comptime std.debug.assert(things.foo == 1); |
| 1604 | 1621 | } |
| 1605 | 1622 | |
| ... | ... | @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { |
| 1608 | 1625 | comptime foo: i8 = 1, |
| 1609 | 1626 | }; |
| 1610 | 1627 | var things = T{}; |
| 1611 | ||
| 1628 | _ = &things; | |
| 1612 | 1629 | comptime std.debug.assert(things.foo == 1); |
| 1613 | 1630 | } |
| 1614 | 1631 | |
| ... | ... | @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { |
| 1616 | 1633 | var things: struct { |
| 1617 | 1634 | comptime foo: i8 = 1, |
| 1618 | 1635 | } = .{}; |
| 1619 | ||
| 1636 | _ = &things; | |
| 1620 | 1637 | comptime std.debug.assert(things.foo == 1); |
| 1621 | 1638 | } |
| 1622 | 1639 | |
| ... | ... | @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { |
| 1624 | 1641 | var things: struct { |
| 1625 | 1642 | comptime foo: i8 = 1, |
| 1626 | 1643 | } = undefined; // Segmentation fault at address 0x0 |
| 1627 | ||
| 1644 | _ = &things; | |
| 1628 | 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 | 1772 | test "pointer to struct initialized through reference to anonymous initializer provides result types" { |
| 1756 | 1773 | const S = struct { a: u8, b: u16, c: *const anyopaque }; |
| 1757 | 1774 | var my_u16: u16 = 0xABCD; |
| 1775 | _ = &my_u16; | |
| 1758 | 1776 | const s: *const S = &.{ |
| 1759 | 1777 | // intentionally out of order |
| 1760 | 1778 | .c = @ptrCast("hello"), |
| ... | ... | @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { |
| 1792 | 1810 | }; |
| 1793 | 1811 | |
| 1794 | 1812 | var s: S = .{}; |
| 1813 | _ = &s; | |
| 1795 | 1814 | try expectEqual(4, @alignOf(S)); |
| 1796 | 1815 | try expectEqual(@as(usize, 5), s.x); |
| 1797 | 1816 | } |
| ... | ... | @@ -1802,6 +1821,7 @@ test "initializer uses own size" { |
| 1802 | 1821 | }; |
| 1803 | 1822 | |
| 1804 | 1823 | var s: S = .{}; |
| 1824 | _ = &s; | |
| 1805 | 1825 | try expectEqual(4, @sizeOf(S)); |
| 1806 | 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 | 1835 | |
| 1816 | 1836 | fn doTheTest() !void { |
| 1817 | 1837 | var foo: S = .{}; |
| 1838 | _ = &foo; | |
| 1818 | 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 | 1860 | }; |
| 1840 | 1861 | }; |
| 1841 | 1862 | var outer: S.StructOuter = .{}; |
| 1863 | _ = &outer; | |
| 1842 | 1864 | try expect(outer.middle.outer == null); |
| 1843 | 1865 | try expect(outer.middle.inner == null); |
| 1844 | 1866 | } |
| ... | ... | @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { |
| 1855 | 1877 | } |
| 1856 | 1878 | }; |
| 1857 | 1879 | var s: S = .{}; |
| 1880 | _ = &s; | |
| 1858 | 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 | 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 8 | 8 | |
| 9 | 9 | var x: ?*NodeLineComment = null; |
| 10 | _ = &x; | |
| 10 | 11 | try expect(x == null); |
| 11 | 12 | } |
| 12 | 13 |
test/behavior/switch.zig+17-9| ... | ... | @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { |
| 157 | 157 | |
| 158 | 158 | test "u0" { |
| 159 | 159 | var val: u0 = 0; |
| 160 | _ = &val; | |
| 160 | 161 | switch (val) { |
| 161 | 162 | 0 => try expect(val == 0), |
| 162 | 163 | } |
| ... | ... | @@ -164,6 +165,7 @@ test "u0" { |
| 164 | 165 | |
| 165 | 166 | test "undefined.u0" { |
| 166 | 167 | var val: u0 = undefined; |
| 168 | _ = &val; | |
| 167 | 169 | switch (val) { |
| 168 | 170 | 0 => try expect(val == 0), |
| 169 | 171 | } |
| ... | ... | @@ -173,6 +175,7 @@ test "switch with disjoint range" { |
| 173 | 175 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 174 | 176 | |
| 175 | 177 | var q: u8 = 0; |
| 178 | _ = &q; | |
| 176 | 179 | switch (q) { |
| 177 | 180 | 0...125 => {}, |
| 178 | 181 | 127...255 => {}, |
| ... | ... | @@ -183,12 +186,8 @@ test "switch with disjoint range" { |
| 183 | 186 | test "switch variable for range and multiple prongs" { |
| 184 | 187 | const S = struct { |
| 185 | 188 | fn doTheTest() !void { |
| 186 | var u: u8 = 16; | |
| 187 | try doTheSwitch(u); | |
| 188 | try comptime doTheSwitch(u); | |
| 189 | var v: u8 = 42; | |
| 190 | try doTheSwitch(v); | |
| 191 | try comptime doTheSwitch(v); | |
| 189 | try doTheSwitch(16); | |
| 190 | try doTheSwitch(42); | |
| 192 | 191 | } |
| 193 | 192 | fn doTheSwitch(q: u8) !void { |
| 194 | 193 | switch (q) { |
| ... | ... | @@ -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 | } |
| 203 | 203 | |
| 204 | 204 | var state: u32 = 0; |
| ... | ... | @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { |
| 322 | 322 | }; |
| 323 | 323 | |
| 324 | 324 | var x: X = X{ .b = 10 }; |
| 325 | var y: i32 = switch (x) { | |
| 325 | _ = &x; | |
| 326 | const y: i32 = switch (x) { | |
| 326 | 327 | .a => unreachable, |
| 327 | 328 | .b => |b| b + 1, |
| 328 | 329 | }; |
| ... | ... | @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { |
| 357 | 358 | }; |
| 358 | 359 | |
| 359 | 360 | var foo = Foo{ .a = 1234 }; |
| 361 | _ = &foo; | |
| 360 | 362 | switch (foo) { |
| 361 | 363 | .a => |x| { |
| 362 | 364 | try expect(x == 1234); |
| ... | ... | @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { |
| 406 | 408 | const S = struct { |
| 407 | 409 | fn doTheTest() !void { |
| 408 | 410 | var x: i32 = 5; |
| 411 | _ = &x; | |
| 409 | 412 | switch (x + 10) { |
| 410 | 413 | 14 => @panic("fail"), |
| 411 | 414 | 16 => @panic("fail"), |
| ... | ... | @@ -606,6 +609,7 @@ test "switch on error set with single else" { |
| 606 | 609 | const S = struct { |
| 607 | 610 | fn doTheTest() !void { |
| 608 | 611 | var some: error{Foo} = error.Foo; |
| 612 | _ = &some; | |
| 609 | 613 | try expect(switch (some) { |
| 610 | 614 | else => blk: { |
| 611 | 615 | break :blk true; |
| ... | ... | @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { |
| 672 | 676 | b = 2, |
| 673 | 677 | _, |
| 674 | 678 | }; |
| 675 | var e: E = @as(E, @enumFromInt(0)); | |
| 679 | var e: E = @enumFromInt(0); | |
| 680 | _ = &e; | |
| 676 | 681 | switch (e) { |
| 677 | 682 | @as(E, @enumFromInt(0)) => {}, |
| 678 | 683 | .a => return error.TestFailed, |
| ... | ... | @@ -685,6 +690,7 @@ test "switch item sizeof" { |
| 685 | 690 | const S = struct { |
| 686 | 691 | fn doTheTest() !void { |
| 687 | 692 | var a: usize = 0; |
| 693 | _ = &a; | |
| 688 | 694 | switch (a) { |
| 689 | 695 | @sizeOf(struct {}) => {}, |
| 690 | 696 | else => return error.TestFailed, |
| ... | ... | @@ -699,6 +705,7 @@ test "comptime inline switch" { |
| 699 | 705 | const U = union(enum) { a: type, b: type }; |
| 700 | 706 | const value = comptime blk: { |
| 701 | 707 | var u: U = .{ .a = u32 }; |
| 708 | _ = &u; | |
| 702 | 709 | break :blk switch (u) { |
| 703 | 710 | inline .a, .b => |v| v, |
| 704 | 711 | }; |
| ... | ... | @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { |
| 814 | 821 | |
| 815 | 822 | // This is runtime-known so the following store isn't comptime-known. |
| 816 | 823 | var rt: u32 = 123; |
| 824 | _ = &rt; | |
| 817 | 825 | val = .{ .a = rt }; // will not necessarily zero remaning payload memory |
| 818 | 826 | |
| 819 | 827 | // Fields intentionally backwards here |
test/behavior/truncate.zig+17-12| ... | ... | @@ -4,58 +4,62 @@ const expect = std.testing.expect; |
| 4 | 4 | |
| 5 | 5 | test "truncate u0 to larger integer allowed and has comptime-known result" { |
| 6 | 6 | var x: u0 = 0; |
| 7 | _ = &x; | |
| 7 | 8 | const y = @as(u8, @truncate(x)); |
| 8 | 9 | try comptime expect(y == 0); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | 12 | test "truncate.u0.literal" { |
| 12 | var z = @as(u0, @truncate(0)); | |
| 13 | const z: u0 = @truncate(0); | |
| 13 | 14 | try expect(z == 0); |
| 14 | 15 | } |
| 15 | 16 | |
| 16 | 17 | test "truncate.u0.const" { |
| 17 | 18 | const c0: usize = 0; |
| 18 | var z = @as(u0, @truncate(c0)); | |
| 19 | const z: u0 = @truncate(c0); | |
| 19 | 20 | try expect(z == 0); |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | 23 | test "truncate.u0.var" { |
| 23 | 24 | var d: u8 = 2; |
| 24 | var z = @as(u0, @truncate(d)); | |
| 25 | _ = &d; | |
| 26 | const z: u0 = @truncate(d); | |
| 25 | 27 | try expect(z == 0); |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | test "truncate i0 to larger integer allowed and has comptime-known result" { |
| 29 | 31 | var x: i0 = 0; |
| 30 | const y = @as(i8, @truncate(x)); | |
| 32 | _ = &x; | |
| 33 | const y: i8 = @truncate(x); | |
| 31 | 34 | try comptime expect(y == 0); |
| 32 | 35 | } |
| 33 | 36 | |
| 34 | 37 | test "truncate.i0.literal" { |
| 35 | var z = @as(i0, @truncate(0)); | |
| 38 | const z: i0 = @truncate(0); | |
| 36 | 39 | try expect(z == 0); |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | 42 | test "truncate.i0.const" { |
| 40 | 43 | const c0: isize = 0; |
| 41 | var z = @as(i0, @truncate(c0)); | |
| 44 | const z: i0 = @truncate(c0); | |
| 42 | 45 | try expect(z == 0); |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | 48 | test "truncate.i0.var" { |
| 46 | 49 | var d: i8 = 2; |
| 47 | var z = @as(i0, @truncate(d)); | |
| 50 | _ = &d; | |
| 51 | const z: i0 = @truncate(d); | |
| 48 | 52 | try expect(z == 0); |
| 49 | 53 | } |
| 50 | 54 | |
| 51 | 55 | test "truncate on comptime integer" { |
| 52 | var x = @as(u16, @truncate(9999)); | |
| 56 | const x: u16 = @truncate(9999); | |
| 53 | 57 | try expect(x == 9999); |
| 54 | var y = @as(u16, @truncate(-21555)); | |
| 58 | const y: u16 = @truncate(-21555); | |
| 55 | 59 | try expect(y == 0xabcd); |
| 56 | var z = @as(i16, @truncate(-65537)); | |
| 60 | const z: i16 = @truncate(-65537); | |
| 57 | 61 | try expect(z == -1); |
| 58 | var w = @as(u1, @truncate(1 << 100)); | |
| 62 | const w: u1 = @truncate(1 << 100); | |
| 59 | 63 | try expect(w == 0); |
| 60 | 64 | } |
| 61 | 65 | |
| ... | ... | @@ -69,7 +73,8 @@ test "truncate on vectors" { |
| 69 | 73 | const S = struct { |
| 70 | 74 | fn doTheTest() !void { |
| 71 | 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 | 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 | 15 | fn doTheTest() !void { |
| 16 | 16 | var a: i32 = 1; |
| 17 | 17 | var b: i32 = 2; |
| 18 | var x = .{a}; | |
| 19 | var y = .{b}; | |
| 20 | var c = x ++ y; | |
| 18 | _ = .{ &a, &b }; | |
| 19 | const x = .{a}; | |
| 20 | const y = .{b}; | |
| 21 | const c = x ++ y; | |
| 21 | 22 | try expect(@as(i32, 1) == c[0]); |
| 22 | 23 | try expect(@as(i32, 2) == c[1]); |
| 23 | 24 | } |
| ... | ... | @@ -119,7 +120,7 @@ test "tuple initializer for var" { |
| 119 | 120 | .id = @as(usize, 2), |
| 120 | 121 | .name = Bytes{ .id = 20 }, |
| 121 | 122 | }; |
| 122 | _ = tmp; | |
| 123 | _ = &tmp; | |
| 123 | 124 | } |
| 124 | 125 | }; |
| 125 | 126 | |
| ... | ... | @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { |
| 157 | 158 | const S = struct { |
| 158 | 159 | fn doTheTest() !void { |
| 159 | 160 | var obj: T = .{ -1234, 128 }; |
| 161 | _ = &obj; | |
| 160 | 162 | try expect(@as(i32, -1234) == obj[0]); |
| 161 | 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 | 173 | fn doTheTest() !void { |
| 172 | 174 | const precomputed = comptime blk: { |
| 173 | 175 | var x: i32 = 1234; |
| 176 | _ = &x; | |
| 174 | 177 | break :blk .{ |
| 175 | 178 | .x = x, |
| 176 | 179 | }; |
| ... | ... | @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { |
| 188 | 191 | fn doTheTest() !void { |
| 189 | 192 | const precomputed = comptime blk: { |
| 190 | 193 | var x: i32 = 1234; |
| 194 | _ = &x; | |
| 191 | 195 | break :blk .{x}; |
| 192 | 196 | }; |
| 193 | 197 | try expect(precomputed[0] == 1234); |
| ... | ... | @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { |
| 201 | 205 | test "initializing tuple with explicit type" { |
| 202 | 206 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); |
| 203 | 207 | var a = T{ 0, 0 }; |
| 204 | _ = a; | |
| 208 | _ = &a; | |
| 205 | 209 | } |
| 206 | 210 | |
| 207 | 211 | test "initializing anon struct with explicit type" { |
| 208 | 212 | const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); |
| 209 | 213 | var a = T{ .foo = 1, .bar = 2 }; |
| 210 | _ = a; | |
| 214 | _ = &a; | |
| 211 | 215 | } |
| 212 | 216 | |
| 213 | 217 | test "fieldParentPtr of tuple" { |
| ... | ... | @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { |
| 216 | 220 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 217 | 221 | |
| 218 | 222 | var x: u32 = 0; |
| 223 | _ = &x; | |
| 219 | 224 | const tuple = .{ x, x }; |
| 220 | 225 | try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); |
| 221 | 226 | } |
| ... | ... | @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { |
| 226 | 231 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 227 | 232 | |
| 228 | 233 | var x: u32 = 0; |
| 234 | _ = &x; | |
| 229 | 235 | const anon_st = .{ .foo = x, .bar = x }; |
| 230 | 236 | try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); |
| 231 | 237 | } |
| 232 | 238 | |
| 233 | 239 | test "offsetOf tuple" { |
| 234 | 240 | var x: u32 = 0; |
| 241 | _ = &x; | |
| 235 | 242 | const T = @TypeOf(.{ x, x }); |
| 236 | 243 | try expect(@offsetOf(T, "1") == @sizeOf(u32)); |
| 237 | 244 | } |
| 238 | 245 | |
| 239 | 246 | test "offsetOf anon struct" { |
| 240 | 247 | var x: u32 = 0; |
| 248 | _ = &x; | |
| 241 | 249 | const T = @TypeOf(.{ .foo = x, .bar = x }); |
| 242 | 250 | try expect(@offsetOf(T, "bar") == @sizeOf(u32)); |
| 243 | 251 | } |
| ... | ... | @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { |
| 247 | 255 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 248 | 256 | |
| 249 | 257 | var x: u32 = 15; |
| 258 | _ = &x; | |
| 250 | 259 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); |
| 251 | 260 | var a: T = .{ -1234, 5678, x + 1 }; |
| 261 | _ = &a; | |
| 252 | 262 | try expect(a[2] == 16); |
| 253 | 263 | } |
| 254 | 264 | |
| ... | ... | @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { |
| 257 | 267 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 258 | 268 | |
| 259 | 269 | var x: u32 = 15; |
| 270 | _ = &x; | |
| 260 | 271 | const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); |
| 261 | 272 | var a: T = .{ .foo = -1234, .bar = x + 1 }; |
| 273 | _ = &a; | |
| 262 | 274 | try expect(a.bar == 16); |
| 263 | 275 | } |
| 264 | 276 | |
| ... | ... | @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { |
| 338 | 350 | |
| 339 | 351 | const T = std.meta.Tuple(&[_]type{ usize, void }); |
| 340 | 352 | var t: T = .{ 5, {} }; |
| 353 | _ = &t; | |
| 341 | 354 | try expect(t[0] == 5); |
| 342 | 355 | } |
| 343 | 356 | |
| ... | ... | @@ -352,6 +365,7 @@ test "branching inside tuple literal" { |
| 352 | 365 | } |
| 353 | 366 | }; |
| 354 | 367 | var a = false; |
| 368 | _ = &a; | |
| 355 | 369 | try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); |
| 356 | 370 | } |
| 357 | 371 | |
| ... | ... | @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { |
| 363 | 377 | const E = union(enum) { e: []const u8 }; |
| 364 | 378 | const W = union(enum) { w: E }; |
| 365 | 379 | var e = E{ .e = "test" }; |
| 380 | _ = &e; | |
| 366 | 381 | const w = .{W{ .w = e }}; |
| 367 | 382 | try expectEqualStrings(w[0].w.e, "test"); |
| 368 | 383 | } |
| ... | ... | @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { |
| 388 | 403 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 389 | 404 | |
| 390 | 405 | var data: u8 = 0; |
| 406 | _ = &data; | |
| 391 | 407 | const x = .{ |
| 392 | 408 | if (data != 0) "" else switch (@as(u1, @truncate(data))) { |
| 393 | 409 | 0 => "up", |
| ... | ... | @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { |
| 446 | 462 | |
| 447 | 463 | var x: u8 = 1; |
| 448 | 464 | var y: u16 = 2; |
| 449 | var t = .{ x, y }; | |
| 450 | var s: struct { u8, u16 } = t; | |
| 465 | _ = .{ &x, &y }; | |
| 466 | const t = .{ x, y }; | |
| 467 | const s: struct { u8, u16 } = t; | |
| 451 | 468 | try expectEqual(x, s[0]); |
| 452 | 469 | try expectEqual(y, s[1]); |
| 453 | 470 | } |
test/behavior/tuple_declarations.zig+4-2| ... | ... | @@ -38,17 +38,19 @@ test "Tuple declaration usage" { |
| 38 | 38 | |
| 39 | 39 | const T = struct { u32, []const u8 }; |
| 40 | 40 | var t: T = .{ 1, "foo" }; |
| 41 | _ = &t; | |
| 41 | 42 | try expect(t[0] == 1); |
| 42 | 43 | try expectEqualStrings(t[1], "foo"); |
| 43 | 44 | |
| 44 | var mul = t ** 3; | |
| 45 | const mul = t ** 3; | |
| 45 | 46 | try expect(@TypeOf(mul) != T); |
| 46 | 47 | try expect(mul.len == 6); |
| 47 | 48 | try expect(mul[2] == 1); |
| 48 | 49 | try expectEqualStrings(mul[3], "foo"); |
| 49 | 50 | |
| 50 | 51 | var t2: T = .{ 2, "bar" }; |
| 51 | var cat = t ++ t2; | |
| 52 | _ = &t2; | |
| 53 | const cat = t ++ t2; | |
| 52 | 54 | try expect(@TypeOf(cat) != T); |
| 53 | 55 | try expect(cat.len == 4); |
| 54 | 56 | try expect(cat[2] == 2); |
test/behavior/type.zig+3-2| ... | ... | @@ -410,7 +410,8 @@ test "Type.Union" { |
| 410 | 410 | .decls = &.{}, |
| 411 | 411 | }, |
| 412 | 412 | }); |
| 413 | var packed_untagged = PackedUntagged{ .signed = -1 }; | |
| 413 | var packed_untagged: PackedUntagged = .{ .signed = -1 }; | |
| 414 | _ = &packed_untagged; | |
| 414 | 415 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); |
| 415 | 416 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); |
| 416 | 417 | |
| ... | ... | @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { |
| 529 | 530 | .decls = &.{}, |
| 530 | 531 | .is_tuple = false, |
| 531 | 532 | } }); |
| 532 | var t: T = .{ .a = 123 }; | |
| 533 | const t: T = .{ .a = 123 }; | |
| 533 | 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 | 417 | } |
| 418 | 418 | }; |
| 419 | 419 | comptime var info = @typeInfo(S); |
| 420 | _ = info; | |
| 420 | _ = &info; | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | test "type info: vectors" { |
test/behavior/union.zig+46-5| ... | ... | @@ -171,6 +171,7 @@ test "constant tagged union with payload" { |
| 171 | 171 | |
| 172 | 172 | var empty = TaggedUnionWithPayload{ .Empty = {} }; |
| 173 | 173 | var full = TaggedUnionWithPayload{ .Full = 13 }; |
| 174 | _ = .{ &empty, &full }; | |
| 174 | 175 | shouldBeEmpty(empty); |
| 175 | 176 | shouldBeNotEmpty(full); |
| 176 | 177 | } |
| ... | ... | @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { |
| 254 | 255 | |
| 255 | 256 | fn testComparison() !void { |
| 256 | 257 | var x = Payload{ .A = 42 }; |
| 258 | _ = &x; | |
| 257 | 259 | try expect(x == .A); |
| 258 | 260 | try expect(x != .B); |
| 259 | 261 | try expect(x != .C); |
| ... | ... | @@ -288,6 +290,7 @@ test "cast union to tag type of union" { |
| 288 | 290 | |
| 289 | 291 | fn testCastUnionToTag() !void { |
| 290 | 292 | var u = TheUnion{ .B = 1234 }; |
| 293 | _ = &u; | |
| 291 | 294 | try expect(@as(TheTag, u) == TheTag.B); |
| 292 | 295 | } |
| 293 | 296 | |
| ... | ... | @@ -303,6 +306,7 @@ test "cast tag type of union to union" { |
| 303 | 306 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 304 | 307 | |
| 305 | 308 | var x: Value2 = Letter2.B; |
| 309 | _ = &x; | |
| 306 | 310 | try expect(@as(Letter2, x) == Letter2.B); |
| 307 | 311 | } |
| 308 | 312 | const Letter2 = enum { A, B, C }; |
| ... | ... | @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { |
| 318 | 322 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 319 | 323 | |
| 320 | 324 | var x: Value2 = Letter2.B; |
| 325 | _ = &x; | |
| 321 | 326 | try expect(x == Letter2.B); |
| 322 | 327 | try giveMeLetterB(x); |
| 323 | 328 | } |
| ... | ... | @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { |
| 356 | 361 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 357 | 362 | |
| 358 | 363 | var x = MultipleChoice.C; |
| 364 | _ = &x; | |
| 359 | 365 | try expect(x == MultipleChoice.C); |
| 360 | 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 | 426 | }; |
| 421 | 427 | |
| 422 | 428 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 429 | _ = &e; | |
| 423 | 430 | const ExprTag = Tag(Expr); |
| 424 | 431 | try comptime expect(Tag(ExprTag) == u0); |
| 425 | 432 | var t = @as(ExprTag, e); |
| 433 | _ = &t; | |
| 426 | 434 | try expect(t == Expr.Literal); |
| 427 | 435 | } |
| 428 | 436 | |
| ... | ... | @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { |
| 494 | 502 | }; |
| 495 | 503 | |
| 496 | 504 | var v = U{ .A = 532 }; |
| 505 | _ = &v; | |
| 497 | 506 | try expect(v.A == 532); |
| 498 | 507 | } |
| 499 | 508 | |
| ... | ... | @@ -506,6 +515,7 @@ test "runtime tag name with single field" { |
| 506 | 515 | }; |
| 507 | 516 | |
| 508 | 517 | var v = U{ .A = 42 }; |
| 518 | _ = &v; | |
| 509 | 519 | try expect(std.mem.eql(u8, @tagName(v), "A")); |
| 510 | 520 | } |
| 511 | 521 | |
| ... | ... | @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 698 | 708 | }; |
| 699 | 709 | |
| 700 | 710 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 711 | _ = &e; | |
| 701 | 712 | try comptime expect(Tag(ExprTag) == comptime_int); |
| 702 | comptime var t = @as(ExprTag, e); | |
| 713 | const t = comptime @as(ExprTag, e); | |
| 703 | 714 | try expect(t == Expr.Literal); |
| 704 | 715 | try expect(@intFromEnum(t) == 33); |
| 705 | 716 | try comptime expect(@intFromEnum(t) == 33); |
| ... | ... | @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { |
| 719 | 730 | const a = Bar{ .A = true }; |
| 720 | 731 | var b = Bar{ .B = undefined }; |
| 721 | 732 | var c = Bar.C; |
| 733 | _ = .{ &b, &c }; | |
| 722 | 734 | try expect(@intFromEnum(a) == 0); |
| 723 | 735 | try expect(@intFromEnum(b) == 1); |
| 724 | 736 | try expect(@intFromEnum(c) == 2); |
| ... | ... | @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { |
| 800 | 812 | fn doTheTest() !void { |
| 801 | 813 | { |
| 802 | 814 | var t = true; |
| 815 | _ = &t; | |
| 803 | 816 | const u = @unionInit(U, "boolean", t); |
| 804 | 817 | try expect(u.boolean); |
| 805 | 818 | } |
| 806 | 819 | { |
| 807 | 820 | var byte: u8 = 69; |
| 821 | _ = &byte; | |
| 808 | 822 | const u = @unionInit(U, "byte", byte); |
| 809 | 823 | try expect(u.byte == 69); |
| 810 | 824 | } |
| ... | ... | @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { |
| 849 | 863 | }; |
| 850 | 864 | |
| 851 | 865 | var value: UnionInitEnum = undefined; |
| 852 | var value_ptr = &value; | |
| 866 | const value_ptr = &value; | |
| 853 | 867 | |
| 854 | 868 | value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); |
| 855 | 869 | try expect(value.Boolean == true); |
| ... | ... | @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { |
| 906 | 920 | |
| 907 | 921 | fn doTheTest() !void { |
| 908 | 922 | var i: Number = .{ .int = 42 }; |
| 909 | var f = makeNumber(); | |
| 923 | _ = &i; | |
| 924 | const f = makeNumber(); | |
| 910 | 925 | try expect(i.int == 42); |
| 911 | 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 | 949 | |
| 935 | 950 | fn doTheTest() !void { |
| 936 | 951 | var x: ArchTag = getArch1(); |
| 952 | _ = &x; | |
| 937 | 953 | try expect(x == .One); |
| 938 | 954 | |
| 939 | 955 | var y: ArchTag = getArch2(); |
| 956 | _ = &y; | |
| 940 | 957 | try expect(y == .Two); |
| 941 | 958 | } |
| 942 | 959 | |
| ... | ... | @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { |
| 965 | 982 | }; |
| 966 | 983 | fn doTheTest() !void { |
| 967 | 984 | var y: u32 = 42; |
| 985 | _ = &y; | |
| 968 | 986 | const t0 = .{ .A = 123 }; |
| 969 | 987 | const t1 = .{ .B = "foo" }; |
| 970 | 988 | const t2 = .{ .C = {} }; |
| 971 | 989 | const t3 = .{ .A = y }; |
| 972 | 990 | const x0: U = t0; |
| 973 | 991 | var x1: U = t1; |
| 992 | _ = &x1; | |
| 974 | 993 | const x2: U = t2; |
| 975 | 994 | var x3: U = t3; |
| 995 | _ = &x3; | |
| 976 | 996 | try expect(x0.A == 123); |
| 977 | 997 | try expect(std.mem.eql(u8, x1.B, "foo")); |
| 978 | 998 | try expect(x2 == .C); |
| ... | ... | @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { |
| 996 | 1016 | }; |
| 997 | 1017 | fn doTheTest() !void { |
| 998 | 1018 | var y: u32 = 42; |
| 1019 | _ = &y; | |
| 999 | 1020 | const t0 = &.{ .A = 123 }; |
| 1000 | 1021 | const t1 = &.{ .B = "foo" }; |
| 1001 | 1022 | const t2 = &.{ .C = {} }; |
| 1002 | 1023 | const t3 = &.{ .A = y }; |
| 1003 | 1024 | const x0: *const U = t0; |
| 1004 | 1025 | var x1: *const U = t1; |
| 1026 | _ = &x1; | |
| 1005 | 1027 | const x2: *const U = t2; |
| 1006 | 1028 | var x3: *const U = t3; |
| 1029 | _ = &x3; | |
| 1007 | 1030 | try expect(x0.A == 123); |
| 1008 | 1031 | try expect(std.mem.eql(u8, x1.B, "foo")); |
| 1009 | 1032 | try expect(x2.* == .C); |
| ... | ... | @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { |
| 1031 | 1054 | }; |
| 1032 | 1055 | fn doTheTest() !void { |
| 1033 | 1056 | var a = U{ .a = 2 }; |
| 1057 | _ = &a; | |
| 1034 | 1058 | switch (a) { |
| 1035 | 1059 | .a => |val| try expect(val == 2), |
| 1036 | 1060 | .b => return error.Fail, |
| ... | ... | @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { |
| 1055 | 1079 | fn doTheTest() !void { |
| 1056 | 1080 | var array1 = [1]A{A{ .f1 = {} }}; |
| 1057 | 1081 | var array2 = [1]B{B{ .f1 = {} }}; |
| 1082 | _ = .{ &array1, &array2 }; | |
| 1058 | 1083 | try expect(array1[0] == .f1); |
| 1059 | 1084 | try expect(array2[0] == .f1); |
| 1060 | 1085 | |
| 1061 | 1086 | var struct1 = C{ .a = A{ .f1 = {} } }; |
| 1062 | 1087 | var struct2 = D{ .a = B{ .f1 = {} } }; |
| 1088 | _ = .{ &struct1, &struct2 }; | |
| 1063 | 1089 | try expect(struct1.a == .f1); |
| 1064 | 1090 | try expect(struct2.a == .f1); |
| 1065 | 1091 | } |
| ... | ... | @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { |
| 1092 | 1118 | |
| 1093 | 1119 | fn doTheTest() !void { |
| 1094 | 1120 | var data: Data = .{ .no_op = {} }; |
| 1095 | _ = data; | |
| 1121 | _ = &data; | |
| 1096 | 1122 | var o = Data.decode(&[_]u8{}); |
| 1123 | _ = &o; | |
| 1097 | 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 | 1183 | } |
| 1157 | 1184 | }; |
| 1158 | 1185 | var a: u32 = 1; |
| 1186 | _ = &a; | |
| 1159 | 1187 | U.foo(U{ .a = a }); |
| 1160 | 1188 | } |
| 1161 | 1189 | |
| ... | ... | @@ -1174,6 +1202,7 @@ test "union with a large struct field" { |
| 1174 | 1202 | fn foo(_: @This()) void {} |
| 1175 | 1203 | }; |
| 1176 | 1204 | var s: S = undefined; |
| 1205 | _ = &s; | |
| 1177 | 1206 | U.foo(U{ .s = s }); |
| 1178 | 1207 | } |
| 1179 | 1208 | |
| ... | ... | @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { |
| 1207 | 1236 | } |
| 1208 | 1237 | }; |
| 1209 | 1238 | var b: u32 = 1; |
| 1239 | _ = &b; | |
| 1210 | 1240 | try (U{ .b = b }).doTheTest(); |
| 1211 | 1241 | } |
| 1212 | 1242 | |
| ... | ... | @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { |
| 1226 | 1256 | un: [110]u8, |
| 1227 | 1257 | }; |
| 1228 | 1258 | var a: ?U = .{ .un = [_]u8{0} ** 110 }; |
| 1259 | _ = &a; | |
| 1229 | 1260 | try expect(a != null); |
| 1230 | 1261 | } |
| 1231 | 1262 | |
| ... | ... | @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { |
| 1246 | 1277 | |
| 1247 | 1278 | fn bar(arg_u: U) callconv(.C) U { |
| 1248 | 1279 | var u = arg_u; |
| 1280 | _ = &u; | |
| 1249 | 1281 | return u; |
| 1250 | 1282 | } |
| 1251 | 1283 | }; |
| ... | ... | @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { |
| 1324 | 1356 | a: usize, |
| 1325 | 1357 | }; |
| 1326 | 1358 | var i: isize = -1; |
| 1359 | _ = &i; | |
| 1327 | 1360 | var u = @unionInit(U, "b", i); |
| 1328 | 1361 | { |
| 1329 | 1362 | var a = u.b; |
| 1363 | _ = &a; | |
| 1330 | 1364 | try expect(a == i); |
| 1331 | 1365 | } |
| 1332 | 1366 | { |
| 1333 | 1367 | var a = &u.b; |
| 1368 | _ = &a; | |
| 1334 | 1369 | try expect(a.* == i); |
| 1335 | 1370 | } |
| 1336 | 1371 | try expect(@intFromEnum(u) == 255); |
| ... | ... | @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { |
| 1508 | 1543 | b: u8, |
| 1509 | 1544 | |
| 1510 | 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 | 1547 | try expect(u == .a); |
| 1513 | 1548 | } |
| 1514 | 1549 | }; |
| ... | ... | @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { |
| 1947 | 1982 | }; |
| 1948 | 1983 | |
| 1949 | 1984 | var s: S = .{}; |
| 1985 | _ = &s; | |
| 1950 | 1986 | try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1951 | 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 | 2002 | }; |
| 1967 | 2003 | |
| 1968 | 2004 | var u: U = reinterpreted; |
| 2005 | _ = &u; | |
| 1969 | 2006 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1970 | 2007 | try expect(u.b == 0xaa); |
| 1971 | 2008 | } |
| ... | ... | @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { |
| 1985 | 2022 | }; |
| 1986 | 2023 | |
| 1987 | 2024 | var u: U = reinterpreted; |
| 2025 | _ = &u; | |
| 1988 | 2026 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1989 | 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 | 2056 | }; |
| 2019 | 2057 | |
| 2020 | 2058 | var x: usize = 42; |
| 2059 | _ = &x; | |
| 2021 | 2060 | try S.taggedUnion(.{ .x = x }); |
| 2022 | 2061 | try S.untaggedUnion(.{ .x = x }); |
| 2023 | 2062 | try S.externUnion(.{ .x = x }); |
| ... | ... | @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { |
| 2039 | 2078 | }; |
| 2040 | 2079 | }; |
| 2041 | 2080 | var outer: S.UnionOuter = .{}; |
| 2081 | _ = &outer; | |
| 2042 | 2082 | try expect(outer.u.outer == null); |
| 2043 | 2083 | try expect(outer.u.inner == null); |
| 2044 | 2084 | } |
| ... | ... | @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { |
| 2057 | 2097 | }; |
| 2058 | 2098 | |
| 2059 | 2099 | var c: u7 = 32; |
| 2100 | _ = &c; | |
| 2060 | 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 | 147 | var runtime: bool = true; |
| 148 | 148 | var a: i32 = 1; |
| 149 | 149 | var b: i32 = 2; |
| 150 | _ = .{ &runtime, &a, &b }; | |
| 150 | 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 | 40 | try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); |
| 41 | 41 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; |
| 42 | 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 | 46 | try S.doTheTest(); |
| ... | ... | @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { |
| 57 | 58 | fn doTheTest() !void { |
| 58 | 59 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 59 | 60 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; |
| 61 | _ = .{ &v, &x }; | |
| 60 | 62 | try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); |
| 61 | 63 | try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); |
| 62 | 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 | 83 | fn doTheTest() !void { |
| 82 | 84 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 83 | 85 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; |
| 86 | _ = .{ &v, &x }; | |
| 84 | 87 | try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); |
| 85 | 88 | try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); |
| 86 | 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 | 108 | fn doTheTest() !void { |
| 106 | 109 | var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; |
| 107 | 110 | var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; |
| 111 | _ = .{ &v, &x }; | |
| 108 | 112 | try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); |
| 109 | 113 | try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); |
| 110 | 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 | 130 | fn doTheTest() !void { |
| 127 | 131 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; |
| 128 | 132 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; |
| 133 | _ = .{ &v, &x }; | |
| 129 | 134 | try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); |
| 130 | 135 | try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); |
| 131 | 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 | 148 | const S = struct { |
| 144 | 149 | fn doTheTest() !void { |
| 145 | 150 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 151 | _ = &a; | |
| 146 | 152 | var result_array: [4]i32 = a; |
| 147 | 153 | result_array = a; |
| 148 | 154 | try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); |
| ... | ... | @@ -160,8 +166,9 @@ test "array to vector" { |
| 160 | 166 | const S = struct { |
| 161 | 167 | fn doTheTest() !void { |
| 162 | 168 | var foo: f32 = 3.14; |
| 163 | var arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; | |
| 164 | var vec: @Vector(4, f32) = arr; | |
| 169 | _ = &foo; | |
| 170 | const arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; | |
| 171 | const vec: @Vector(4, f32) = arr; | |
| 165 | 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 | 187 | const S = struct { |
| 181 | 188 | fn doTheTest() !void { |
| 182 | 189 | var foo1: i48 = 124578; |
| 183 | var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; | |
| 184 | var arr1: [2]i48 = vec1; | |
| 190 | _ = &foo1; | |
| 191 | const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; | |
| 192 | const arr1: [2]i48 = vec1; | |
| 185 | 193 | try expect(vec1[0] == foo1 and vec1[1] == 1); |
| 186 | 194 | try expect(arr1[0] == foo1 and arr1[1] == 1); |
| 187 | 195 | |
| 188 | 196 | var foo2: u4 = 5; |
| 189 | var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; | |
| 190 | var arr2: [2]u4 = vec2; | |
| 197 | _ = &foo2; | |
| 198 | const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; | |
| 199 | const arr2: [2]u4 = vec2; | |
| 191 | 200 | try expect(vec2[0] == foo2 and vec2[1] == 1); |
| 192 | 201 | try expect(arr2[0] == foo2 and arr2[1] == 1); |
| 193 | 202 | |
| 194 | 203 | var foo3: u13 = 13; |
| 195 | var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; | |
| 196 | var arr3: [3]u13 = vec3; | |
| 204 | _ = &foo3; | |
| 205 | const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; | |
| 206 | const arr3: [3]u13 = vec3; | |
| 197 | 207 | try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); |
| 198 | 208 | try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); |
| 199 | 209 | |
| 200 | var arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; | |
| 201 | var vec4: @Vector(4, u24) = arr4; | |
| 210 | const arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; | |
| 211 | const vec4: @Vector(4, u24) = arr4; | |
| 202 | 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 | 227 | const S = struct { |
| 218 | 228 | fn doTheTest() !void { |
| 219 | 229 | var foo: f16 = 3.14; |
| 220 | var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; | |
| 221 | var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; | |
| 230 | _ = &foo; | |
| 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 | 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 | 248 | var b: @Vector(2, u8) = .{ 1, 2 }; |
| 238 | 249 | var a: @Vector(2, u16) = .{ 2, 1 }; |
| 239 | 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 | 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 | 297 | fn doTheTest() !void { |
| 286 | 298 | { |
| 287 | 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 | 302 | try expect(mem.eql(u3, &x, &@as([4]u3, v))); |
| 290 | 303 | } |
| 291 | 304 | { |
| 292 | 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 | 308 | try expect(mem.eql(u2, &x, &@as([4]u2, v))); |
| 295 | 309 | } |
| 296 | 310 | { |
| 297 | 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 | 314 | try expect(mem.eql(u1, &x, &@as([4]u1, v))); |
| 300 | 315 | } |
| 301 | 316 | { |
| 302 | 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 | 320 | try expect(mem.eql(bool, &x, &@as([4]bool, v))); |
| 305 | 321 | } |
| 306 | 322 | } |
| ... | ... | @@ -327,7 +343,8 @@ test "vector @splat" { |
| 327 | 343 | fn testForT(comptime N: comptime_int, v: anytype) !void { |
| 328 | 344 | const T = @TypeOf(v); |
| 329 | 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 | 348 | for (as_array) |elem| try expect(v == elem); |
| 332 | 349 | } |
| 333 | 350 | fn doTheTest() !void { |
| ... | ... | @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { |
| 412 | 429 | const S = struct { |
| 413 | 430 | fn doTheTest() !void { |
| 414 | 431 | var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; |
| 432 | _ = &v; | |
| 415 | 433 | var i: u32 = 0; |
| 416 | 434 | try expect(v[i] == 1); |
| 417 | 435 | i += 1; |
| ... | ... | @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { |
| 461 | 479 | var foo = Vec4Obj{ |
| 462 | 480 | .data = [_]f32{ 1, 2, 3, 4 }, |
| 463 | 481 | }; |
| 464 | _ = foo; | |
| 482 | _ = &foo; | |
| 465 | 483 | } |
| 466 | 484 | }; |
| 467 | 485 | try S.doTheTest(); |
| ... | ... | @@ -481,6 +499,7 @@ test "vector comparison operators" { |
| 481 | 499 | const V = @Vector(4, bool); |
| 482 | 500 | var v1: V = [_]bool{ true, false, true, false }; |
| 483 | 501 | var v2: V = [_]bool{ false, true, false, true }; |
| 502 | _ = .{ &v1, &v2 }; | |
| 484 | 503 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); |
| 485 | 504 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); |
| 486 | 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 | 510 | var v1: @Vector(4, u32) = @splat(0xc0ffeeee); |
| 492 | 511 | var v2: @Vector(4, c_uint) = v1; |
| 493 | 512 | var v3: @Vector(4, u32) = @splat(0xdeadbeef); |
| 513 | _ = .{ &v1, &v2, &v3 }; | |
| 494 | 514 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); |
| 495 | 515 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); |
| 496 | 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 | 519 | { |
| 500 | 520 | // Comptime-known LHS/RHS |
| 501 | 521 | var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; |
| 522 | _ = &v1; | |
| 502 | 523 | const v2: @Vector(4, u32) = @splat(2); |
| 503 | 524 | const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; |
| 504 | 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 | 625 | |
| 605 | 626 | const S = struct { |
| 606 | 627 | fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { |
| 607 | var y = ~x; | |
| 628 | const y = ~x; | |
| 608 | 629 | for (@as([4]T, y), 0..) |v, i| { |
| 609 | 630 | try expect(~x[i] == v); |
| 610 | 631 | } |
| ... | ... | @@ -640,14 +661,14 @@ test "vector shift operators" { |
| 640 | 661 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 641 | 662 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| 642 | 663 | |
| 643 | var xv = @as(@Vector(N, TX), x); | |
| 644 | var yv = @as(@Vector(N, TY), y); | |
| 664 | const xv = @as(@Vector(N, TX), x); | |
| 665 | const yv = @as(@Vector(N, TY), y); | |
| 645 | 666 | |
| 646 | var z0 = xv >> yv; | |
| 667 | const z0 = xv >> yv; | |
| 647 | 668 | for (@as([N]TX, z0), 0..) |v, i| { |
| 648 | 669 | try expect(x[i] >> y[i] == v); |
| 649 | 670 | } |
| 650 | var z1 = xv << yv; | |
| 671 | const z1 = xv << yv; | |
| 651 | 672 | for (@as([N]TX, z1), 0..) |v, i| { |
| 652 | 673 | try expect(x[i] << y[i] == v); |
| 653 | 674 | } |
| ... | ... | @@ -657,10 +678,10 @@ test "vector shift operators" { |
| 657 | 678 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 658 | 679 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| 659 | 680 | |
| 660 | var xv = @as(@Vector(N, TX), x); | |
| 661 | var yv = @as(@Vector(N, TY), y); | |
| 681 | const xv = @as(@Vector(N, TX), x); | |
| 682 | const yv = @as(@Vector(N, TY), y); | |
| 662 | 683 | |
| 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 | 685 | for (@as([N]TX, z), 0..) |v, i| { |
| 665 | 686 | const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; |
| 666 | 687 | try expect(check == v); |
| ... | ... | @@ -734,7 +755,7 @@ test "vector reduce operation" { |
| 734 | 755 | const N = @typeInfo(@TypeOf(x)).Array.len; |
| 735 | 756 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 736 | 757 | |
| 737 | var r = @reduce(op, @as(@Vector(N, TX), x)); | |
| 758 | const r = @reduce(op, @as(@Vector(N, TX), x)); | |
| 738 | 759 | switch (@typeInfo(TX)) { |
| 739 | 760 | .Int, .Bool => try expect(expected == r), |
| 740 | 761 | .Float => { |
| ... | ... | @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { |
| 892 | 913 | const __v4hi = @Vector(4, i16); |
| 893 | 914 | var v4_a = __v4hi{ 0, 0, 0, 0 }; |
| 894 | 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 | 918 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| 897 | 919 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| 898 | 920 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| ... | ... | @@ -915,7 +937,8 @@ test "saturating add" { |
| 915 | 937 | const u8x3 = @Vector(3, u8); |
| 916 | 938 | var lhs = u8x3{ 255, 254, 1 }; |
| 917 | 939 | var rhs = u8x3{ 1, 2, 255 }; |
| 918 | var result = lhs +| rhs; | |
| 940 | _ = .{ &lhs, &rhs }; | |
| 941 | const result = lhs +| rhs; | |
| 919 | 942 | const expected = u8x3{ 255, 255, 255 }; |
| 920 | 943 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 921 | 944 | } |
| ... | ... | @@ -923,7 +946,8 @@ test "saturating add" { |
| 923 | 946 | const i8x3 = @Vector(3, i8); |
| 924 | 947 | var lhs = i8x3{ 127, 126, 1 }; |
| 925 | 948 | var rhs = i8x3{ 1, 2, 127 }; |
| 926 | var result = lhs +| rhs; | |
| 949 | _ = .{ &lhs, &rhs }; | |
| 950 | const result = lhs +| rhs; | |
| 927 | 951 | const expected = i8x3{ 127, 127, 127 }; |
| 928 | 952 | try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); |
| 929 | 953 | } |
| ... | ... | @@ -947,7 +971,8 @@ test "saturating subtraction" { |
| 947 | 971 | const u8x3 = @Vector(3, u8); |
| 948 | 972 | var lhs = u8x3{ 0, 0, 0 }; |
| 949 | 973 | var rhs = u8x3{ 255, 255, 255 }; |
| 950 | var result = lhs -| rhs; | |
| 974 | _ = .{ &lhs, &rhs }; | |
| 975 | const result = lhs -| rhs; | |
| 951 | 976 | const expected = u8x3{ 0, 0, 0 }; |
| 952 | 977 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 953 | 978 | } |
| ... | ... | @@ -973,7 +998,8 @@ test "saturating multiplication" { |
| 973 | 998 | const u8x3 = @Vector(3, u8); |
| 974 | 999 | var lhs = u8x3{ 2, 2, 2 }; |
| 975 | 1000 | var rhs = u8x3{ 255, 255, 255 }; |
| 976 | var result = lhs *| rhs; | |
| 1001 | _ = .{ &lhs, &rhs }; | |
| 1002 | const result = lhs *| rhs; | |
| 977 | 1003 | const expected = u8x3{ 255, 255, 255 }; |
| 978 | 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 | 1023 | const u8x3 = @Vector(3, u8); |
| 998 | 1024 | var lhs = u8x3{ 1, 1, 1 }; |
| 999 | 1025 | var rhs = u8x3{ 255, 255, 255 }; |
| 1000 | var result = lhs <<| rhs; | |
| 1026 | _ = .{ &lhs, &rhs }; | |
| 1027 | const result = lhs <<| rhs; | |
| 1001 | 1028 | const expected = u8x3{ 255, 255, 255 }; |
| 1002 | 1029 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 1003 | 1030 | } |
| ... | ... | @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { |
| 1040 | 1067 | { |
| 1041 | 1068 | var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; |
| 1042 | 1069 | var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; |
| 1043 | var overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1044 | var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | |
| 1070 | _ = .{ &lhs, &rhs }; | |
| 1071 | const overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1072 | const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | |
| 1045 | 1073 | try expectEqual(expected, overflow); |
| 1046 | 1074 | } |
| 1047 | 1075 | { |
| 1048 | 1076 | var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; |
| 1049 | 1077 | var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; |
| 1050 | var overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1051 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1078 | _ = .{ &lhs, &rhs }; | |
| 1079 | const overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1080 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1052 | 1081 | try expectEqual(expected, overflow); |
| 1053 | 1082 | } |
| 1054 | 1083 | { |
| 1055 | 1084 | var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; |
| 1056 | 1085 | var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; |
| 1057 | var overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1058 | var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; | |
| 1086 | _ = .{ &lhs, &rhs }; | |
| 1087 | const overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1088 | const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; | |
| 1059 | 1089 | try expectEqual(expected, overflow); |
| 1060 | 1090 | } |
| 1061 | 1091 | { |
| 1062 | 1092 | var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; |
| 1063 | 1093 | var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; |
| 1064 | var overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1065 | var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; | |
| 1094 | _ = .{ &lhs, &rhs }; | |
| 1095 | const overflow = @addWithOverflow(lhs, rhs)[1]; | |
| 1096 | const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; | |
| 1066 | 1097 | try expectEqual(expected, overflow); |
| 1067 | 1098 | } |
| 1068 | 1099 | } |
| ... | ... | @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { |
| 1084 | 1115 | { |
| 1085 | 1116 | var lhs = @Vector(2, u8){ 5, 5 }; |
| 1086 | 1117 | var rhs = @Vector(2, u8){ 5, 6 }; |
| 1087 | var overflow = @subWithOverflow(lhs, rhs)[1]; | |
| 1088 | var expected: @Vector(2, u1) = .{ 0, 1 }; | |
| 1118 | _ = .{ &lhs, &rhs }; | |
| 1119 | const overflow = @subWithOverflow(lhs, rhs)[1]; | |
| 1120 | const expected: @Vector(2, u1) = .{ 0, 1 }; | |
| 1089 | 1121 | try expectEqual(expected, overflow); |
| 1090 | 1122 | } |
| 1091 | 1123 | { |
| 1092 | 1124 | var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; |
| 1093 | 1125 | var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; |
| 1094 | var overflow = @subWithOverflow(lhs, rhs)[1]; | |
| 1095 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1126 | _ = .{ &lhs, &rhs }; | |
| 1127 | const overflow = @subWithOverflow(lhs, rhs)[1]; | |
| 1128 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1096 | 1129 | try expectEqual(expected, overflow); |
| 1097 | 1130 | } |
| 1098 | 1131 | } |
| ... | ... | @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { |
| 1113 | 1146 | fn doTheTest() !void { |
| 1114 | 1147 | var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; |
| 1115 | 1148 | var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; |
| 1116 | var overflow = @mulWithOverflow(lhs, rhs)[1]; | |
| 1117 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1149 | _ = .{ &lhs, &rhs }; | |
| 1150 | const overflow = @mulWithOverflow(lhs, rhs)[1]; | |
| 1151 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | |
| 1118 | 1152 | try expectEqual(expected, overflow); |
| 1119 | 1153 | } |
| 1120 | 1154 | }; |
| ... | ... | @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { |
| 1134 | 1168 | fn doTheTest() !void { |
| 1135 | 1169 | var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; |
| 1136 | 1170 | var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; |
| 1137 | var overflow = @shlWithOverflow(lhs, rhs)[1]; | |
| 1138 | var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | |
| 1171 | _ = .{ &lhs, &rhs }; | |
| 1172 | const overflow = @shlWithOverflow(lhs, rhs)[1]; | |
| 1173 | const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | |
| 1139 | 1174 | try expectEqual(expected, overflow); |
| 1140 | 1175 | } |
| 1141 | 1176 | }; |
| ... | ... | @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { |
| 1161 | 1196 | @Vector(2, u8){ 0, 1 }, |
| 1162 | 1197 | @Vector(2, u8){ 2, 3 }, |
| 1163 | 1198 | }; |
| 1164 | var a: []const @Vector(2, u8) = &small_bases; | |
| 1165 | var a4 = a[1][1]; | |
| 1199 | const a: []const @Vector(2, u8) = &small_bases; | |
| 1200 | const a4 = a[1][1]; | |
| 1166 | 1201 | try expect(a4 == 3); |
| 1167 | 1202 | } |
| 1168 | 1203 | |
| ... | ... | @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { |
| 1183 | 1218 | Vec3{ -345, -311, 381 }, |
| 1184 | 1219 | Vec3{ -661, -816, -575 }, |
| 1185 | 1220 | }; |
| 1221 | _ = &points; | |
| 1186 | 1222 | var points2: [20]Vec3 = undefined; |
| 1187 | 1223 | points2[0..points.len].* = points; |
| 1188 | 1224 | try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); |
| ... | ... | @@ -1244,6 +1280,7 @@ test "zero multiplicand" { |
| 1244 | 1280 | |
| 1245 | 1281 | const zeros = @Vector(2, u32){ 0.0, 0.0 }; |
| 1246 | 1282 | var ones = @Vector(2, u32){ 1.0, 1.0 }; |
| 1283 | _ = &ones; | |
| 1247 | 1284 | |
| 1248 | 1285 | _ = (ones * zeros)[0]; |
| 1249 | 1286 | _ = (zeros * zeros)[0]; |
| ... | ... | @@ -1266,6 +1303,7 @@ test "@intCast to u0" { |
| 1266 | 1303 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 1267 | 1304 | |
| 1268 | 1305 | var zeros = @Vector(2, u32){ 0, 0 }; |
| 1306 | _ = &zeros; | |
| 1269 | 1307 | const casted = @as(@Vector(2, u0), @intCast(zeros)); |
| 1270 | 1308 | |
| 1271 | 1309 | _ = casted[0]; |
| ... | ... | @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { |
| 1292 | 1330 | const mask = [5]i32{ -1, 0, 1, 2, 3 }; |
| 1293 | 1331 | |
| 1294 | 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 | 1335 | try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); |
| 1297 | 1336 | } |
| 1298 | 1337 | |
| ... | ... | @@ -1320,6 +1359,7 @@ test "store packed vector element" { |
| 1320 | 1359 | var v = @Vector(4, u1){ 1, 1, 1, 1 }; |
| 1321 | 1360 | try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); |
| 1322 | 1361 | var index: usize = 0; |
| 1362 | _ = &index; | |
| 1323 | 1363 | v[index] = 0; |
| 1324 | 1364 | try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); |
| 1325 | 1365 | } |
| ... | ... | @@ -1337,6 +1377,7 @@ test "store to vector in slice" { |
| 1337 | 1377 | }; |
| 1338 | 1378 | var s: []@Vector(3, f32) = &v; |
| 1339 | 1379 | var i: usize = 1; |
| 1380 | _ = &i; | |
| 1340 | 1381 | s[i] = s[0]; |
| 1341 | 1382 | try expectEqual(v[1], v[0]); |
| 1342 | 1383 | } |
| ... | ... | @@ -1378,6 +1419,7 @@ test "store vector with memset" { |
| 1378 | 1419 | var kc = @Vector(2, i4){ 2, 3 }; |
| 1379 | 1420 | var kd = @Vector(2, u8){ 4, 5 }; |
| 1380 | 1421 | var ke = @Vector(2, i9){ 6, 7 }; |
| 1422 | _ = .{ &ka, &kb, &kc, &kd, &ke }; | |
| 1381 | 1423 | @memset(&a, ka); |
| 1382 | 1424 | @memset(&b, kb); |
| 1383 | 1425 | @memset(&c, kc); |
| ... | ... | @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { |
| 1410 | 1452 | |
| 1411 | 1453 | var a: @Vector(2, u8) = .{ 1, 2 }; |
| 1412 | 1454 | var b: @Vector(2, u9) = .{ 3, 0 }; |
| 1455 | _ = .{ &a, &b }; | |
| 1413 | 1456 | try expectEqual(@Vector(2, bool){ true, false }, a < b); |
| 1414 | 1457 | } |
| 1415 | 1458 | |
| ... | ... | @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { |
| 1465 | 1508 | const VecB = @Vector(4, u32); |
| 1466 | 1509 | |
| 1467 | 1510 | var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 1468 | var vec_b: VecB = @bitCast(vec_a); | |
| 1469 | var vec_c: VecA = @bitCast(vec_b); | |
| 1511 | _ = &vec_a; | |
| 1512 | const vec_b: VecB = @bitCast(vec_a); | |
| 1513 | const vec_c: VecA = @bitCast(vec_b); | |
| 1470 | 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 | 38 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 39 | 39 | |
| 40 | 40 | var x: ?void = {}; |
| 41 | _ = &x; | |
| 41 | 42 | try expect(x != null); |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | test "void array as a local variable initializer" { |
| 45 | 46 | var x = [_]void{{}} ** 1004; |
| 47 | _ = &x[0]; | |
| 46 | 48 | _ = x[0]; |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | const void_constant = {}; |
| 50 | 52 | test "reference to void constants" { |
| 51 | 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 | 4 | |
| 5 | 5 | test "memory size and grow" { |
| 6 | 6 | var prev = @wasmMemorySize(0); |
| 7 | _ = &prev; | |
| 7 | 8 | try expect(prev == @wasmMemoryGrow(0, 1)); |
| 8 | 9 | try expect(prev + 1 == @wasmMemorySize(0)); |
| 9 | 10 | } |
test/behavior/widening.zig+5| ... | ... | @@ -15,6 +15,7 @@ test "integer widening" { |
| 15 | 15 | var d: u64 = c; |
| 16 | 16 | var e: u64 = d; |
| 17 | 17 | var f: u128 = e; |
| 18 | _ = .{ &a, &b, &c, &d, &e, &f }; | |
| 18 | 19 | try expect(f == a); |
| 19 | 20 | } |
| 20 | 21 | |
| ... | ... | @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { |
| 33 | 34 | |
| 34 | 35 | var a: u8 = 250; |
| 35 | 36 | var b: i16 = a; |
| 37 | _ = .{ &a, &b }; | |
| 36 | 38 | try expect(b == 250); |
| 37 | 39 | } |
| 38 | 40 | |
| ... | ... | @@ -47,10 +49,12 @@ test "float widening" { |
| 47 | 49 | var b: f32 = a; |
| 48 | 50 | var c: f64 = b; |
| 49 | 51 | var d: f128 = c; |
| 52 | _ = .{ &a, &b, &c, &d }; | |
| 50 | 53 | try expect(a == b); |
| 51 | 54 | try expect(b == c); |
| 52 | 55 | try expect(c == d); |
| 53 | 56 | var e: f80 = c; |
| 57 | _ = &e; | |
| 54 | 58 | try expect(c == e); |
| 55 | 59 | } |
| 56 | 60 | |
| ... | ... | @@ -63,6 +67,7 @@ test "float widening f16 to f128" { |
| 63 | 67 | |
| 64 | 68 | var x: f16 = 12.34; |
| 65 | 69 | var y: f128 = x; |
| 70 | _ = .{ &x, &y }; | |
| 66 | 71 | try expect(x == y); |
| 67 | 72 | } |
| 68 | 73 |