| ... | ... | @@ -30,13 +30,41 @@ test "slicing array of length 1 can not assume runtime index is always zero" { |
| 30 | 30 | var runtime_index: usize = 1; |
| 31 | 31 | _ = &runtime_index; |
| 32 | 32 | const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; |
| 33 | | try expect(@TypeOf(slice) == []u8); |
| 33 | try expect(@TypeOf(slice) == []align(1) u8); |
| 34 | 34 | try expect(slice.len == 0); |
| 35 | 35 | try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | | test "default alignment allows unspecified in type syntax" { |
| 39 | | try expect(*u32 == *align(@alignOf(u32)) u32); |
| 38 | test "implicitly-aligned pointer is coercible to equivalent explicitly-aligned pointer" { |
| 39 | const A = *u32; |
| 40 | const B = *align(@alignOf(u32)) u32; |
| 41 | |
| 42 | comptime assert(A != B); |
| 43 | |
| 44 | const static = struct { |
| 45 | fn doTheTest() !void { |
| 46 | var buf: u32 = 123; |
| 47 | |
| 48 | const ptr: A = &buf; |
| 49 | const coerced_ptr: B = ptr; |
| 50 | |
| 51 | try expect(ptr == coerced_ptr); |
| 52 | try expect(ptr.* == 123); |
| 53 | try expect(coerced_ptr.* == 123); |
| 54 | |
| 55 | const ptr_ptr: *const A = &ptr; |
| 56 | const coerced_ptr_ptr: *const B = ptr_ptr; |
| 57 | |
| 58 | try expect(ptr_ptr == coerced_ptr_ptr); |
| 59 | try expect(ptr_ptr.* == &buf); |
| 60 | try expect(coerced_ptr_ptr.* == &buf); |
| 61 | try expect(ptr_ptr.*.* == 123); |
| 62 | try expect(coerced_ptr_ptr.*.* == 123); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | try static.doTheTest(); |
| 67 | try comptime static.doTheTest(); |
| 40 | 68 | } |
| 41 | 69 | |
| 42 | 70 | test "implicitly decreasing pointer alignment" { |