diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-14 00:40:39 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-14 00:40:39 -0500 |
| commit | d4d2718bca9e23ceec029bb505c0ea1b91c875b6 (patch) | |
| tree | c2b7b61f36fff694f5ff030fde50846b23c690cd /test/compile_errors.zig | |
| parent | 5699ab5e77f8d13cac1e34775e6e51358119965c (diff) | |
| download | zig-d4d2718bca9e23ceec029bb505c0ea1b91c875b6.tar.gz zig-d4d2718bca9e23ceec029bb505c0ea1b91c875b6.zip | |
comptime detection of casting null to pointer
See #1059
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index c51a65cadf..71ee4901ff 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,26 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { cases.addTest( + "implicit casting null c pointer to zig pointer", + \\comptime { + \\ var c_ptr: [*c]u8 = 0; + \\ var zig_ptr: *u8 = c_ptr; + \\} + , + ".tmp_source.zig:3:24: error: null pointer casted to type '*u8'", + ); + + cases.addTest( + "implicit casting undefined c pointer to zig pointer", + \\comptime { + \\ var c_ptr: [*c]u8 = undefined; + \\ var zig_ptr: *u8 = c_ptr; + \\} + , + ".tmp_source.zig:3:24: error: use of undefined value here causes undefined behavior", + ); + + cases.addTest( "implicit casting C pointers which would mess up null semantics", \\export fn entry() void { \\ var slice: []const u8 = "aoeu"; |
