aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-01-06 14:00:34 -0500
committerGitHub <noreply@github.com>2019-01-06 14:00:34 -0500
commit013c7b24d2a2c1f81d2fbcd7c2d07ed582b7acd9 (patch)
tree8b9e743583fb1e6fa379d6ee84593ab94d19fe60 /test
parent5f26d1dddbe9004429adca6e55d3344ca58062ae (diff)
parentda08525bb31c3608667254132b65e409f5869a03 (diff)
downloadzig-013c7b24d2a2c1f81d2fbcd7c2d07ed582b7acd9.tar.gz
zig-013c7b24d2a2c1f81d2fbcd7c2d07ed582b7acd9.zip
Merge pull request #1874 from ziglang/issue-1866
Fix #1866
Diffstat (limited to 'test')
-rw-r--r--test/cases/ptrcast.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/cases/ptrcast.zig b/test/cases/ptrcast.zig
index 6f0e6e5946..54c3dda849 100644
--- a/test/cases/ptrcast.zig
+++ b/test/cases/ptrcast.zig
@@ -34,3 +34,19 @@ fn testReinterpretBytesAsExternStruct() void {
var val = ptr.c;
assertOrPanic(val == 5);
}
+
+test "reinterpret struct field at comptime" {
+ const numLittle = comptime Bytes.init(0x12345678);
+ assertOrPanic(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
+}
+
+const Bytes = struct {
+ bytes: [4]u8,
+
+ pub fn init(v: u32) Bytes {
+ var res: Bytes = undefined;
+ @ptrCast(*align(1) u32, &res.bytes).* = v;
+
+ return res;
+ }
+};