langref: docs for invalid error set cast and incorrect pointer alignment

also add detection of incorrect pointer alignment at compile-time
of pointers that were constructed with `@intToPtr`.
This commit is contained in:
Andrew Kelley
2018-07-09 11:13:29 -04:00
parent 9eb51e20ed
commit 2ee67b7642
3 changed files with 70 additions and 3 deletions

View File

@@ -1,6 +1,16 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"bad @alignCast at comptime",
\\comptime {
\\ const ptr = @intToPtr(*i32, 0x1);
\\ const aligned = @alignCast(4, ptr);
\\}
,
".tmp_source.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes",
);
cases.add(
"@ptrToInt on *void",
\\export fn entry() bool {