diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-09-23 12:43:01 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-23 17:39:06 +0300 |
| commit | 3de5c3b5038d03759d8f5521627fdbbcad28c795 (patch) | |
| tree | bc15e22562a59f73c478454290fe4307d1a163be /test | |
| parent | 8d1fdfc8ede94b1aea524041c1df10c42d4002e4 (diff) | |
| download | zig-3de5c3b5038d03759d8f5521627fdbbcad28c795.tar.gz zig-3de5c3b5038d03759d8f5521627fdbbcad28c795.zip | |
Sema: check for slices in packed and extern type validation
Closes #12930
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig | 7 | ||||
| -rw-r--r-- | test/cases/compile_errors/slice_used_as_extern_fn_param.zig | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig b/test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig index 8fcd300629..fd98db04c8 100644 --- a/test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig +++ b/test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig @@ -60,6 +60,11 @@ const U = extern union { A: i32, B: u32, }; +export fn entry12() void { + _ = @sizeOf(packed struct { + x: packed struct { a: []u8 }, + }); +} // error // backend=llvm @@ -82,3 +87,5 @@ const U = extern union { // :38:9: error: packed structs cannot contain fields of type 'fn() void' // :38:9: note: type has no guaranteed in-memory representation // :38:9: note: use '*const ' to make a function pointer type +// :65:28: error: packed structs cannot contain fields of type '[]u8' +// :65:28: note: slices have no guaranteed in-memory representation diff --git a/test/cases/compile_errors/slice_used_as_extern_fn_param.zig b/test/cases/compile_errors/slice_used_as_extern_fn_param.zig new file mode 100644 index 0000000000..8391c3e21b --- /dev/null +++ b/test/cases/compile_errors/slice_used_as_extern_fn_param.zig @@ -0,0 +1,11 @@ +extern fn Text(str: []const u8, num: i32) callconv(.C) void; +export fn entry() void { + _ = Text; +} + +// error +// backend=stage2 +// target=native +// +// :1:16: error: parameter of type '[]const u8' not allowed in function with calling convention 'C' +// :1:16: note: slices have no guaranteed in-memory representation |
