From 816689a3b1c98ec008438e7f868e1a123889b2a7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Aug 2017 16:52:31 -0400 Subject: ptrCast gives compile error for increasing alignment See #37 --- test/compile_errors.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 03110f98e7..96898d1744 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2011,4 +2011,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) { \\} , ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align 1 u32'"); + + cases.add("increase pointer alignment in @ptrCast", + \\export fn entry() -> u32 { + \\ var bytes: [4]u8 align 4 = []u8{0x01, 0x02, 0x03, 0x04}; + \\ const ptr = @ptrCast(&u32, &bytes[0]); + \\ return *ptr; + \\} + , + ".tmp_source.zig:3:17: error: cast increases pointer alignment", + ".tmp_source.zig:3:38: note: '&u8' has alignment 1", + ".tmp_source.zig:3:27: note: '&u32' has alignment 4"); } -- cgit v1.2.3