diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2018-12-17 11:05:50 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2018-12-17 11:05:50 -0500 |
| commit | f75262b79f0656ebfac7fb5bd2d6d8e8cce01258 (patch) | |
| tree | 6c8ac544c9d56c1f6381da557ec3e6512a1a66ea /test/cases | |
| parent | 5a68c600235fb7cc0e1bf6a8b314e37890e3823b (diff) | |
| download | zig-f75262b79f0656ebfac7fb5bd2d6d8e8cce01258.tar.gz zig-f75262b79f0656ebfac7fb5bd2d6d8e8cce01258.zip | |
fix comptime pointer reinterpretation array index offset
closes #1835
Diffstat (limited to 'test/cases')
| -rw-r--r-- | test/cases/ptrcast.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/cases/ptrcast.zig b/test/cases/ptrcast.zig new file mode 100644 index 0000000000..071087c5c4 --- /dev/null +++ b/test/cases/ptrcast.zig @@ -0,0 +1,17 @@ +const builtin = @import("builtin"); +const std = @import("std"); +const assertOrPanic = std.debug.assertOrPanic; + +test "reinterpret bytes as integer with nonzero offset" { + testReinterpretBytesAsInteger(); + comptime testReinterpretBytesAsInteger(); +} + +fn testReinterpretBytesAsInteger() void { + const bytes = "\x12\x34\x56\x78\xab"; + const expected = switch (builtin.endian) { + builtin.Endian.Little => 0xab785634, + builtin.Endian.Big => 0x345678ab, + }; + assertOrPanic(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected); +} |
