diff options
| author | AdamGoertz <36753247+AdamGoertz@users.noreply.github.com> | 2023-07-29 12:45:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-29 12:45:01 -0400 |
| commit | 796927b900ad4b774c30d1cb545d606f23040d2f (patch) | |
| tree | 7fd53185ae5dfadce29a8ab95f27d5bade0ae05c /src/Sema.zig | |
| parent | 8d1805f81c97a0b773772e86aa39f26c894b7985 (diff) | |
| download | zig-796927b900ad4b774c30d1cb545d606f23040d2f.tar.gz zig-796927b900ad4b774c30d1cb545d606f23040d2f.zip | |
Allow zero-sized fields in extern structs (#16404)
This change allows the following types to appear in extern structs:
* Zero-bit integers
* void
* zero-sized structs and packed structs
* enums with zero-bit backing integers
* arrays of any length with zero-size elements
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 21cbd0cf35..dd5264c6e8 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -24590,7 +24590,7 @@ fn validateExternType( .ErrorSet, .Frame, => return false, - .Void => return position == .union_field or position == .ret_ty, + .Void => return position == .union_field or position == .ret_ty or position == .struct_field or position == .element, .NoReturn => return position == .ret_ty, .Opaque, .Bool, @@ -24599,7 +24599,7 @@ fn validateExternType( => return true, .Pointer => return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty)), .Int => switch (ty.intInfo(mod).bits) { - 8, 16, 32, 64, 128 => return true, + 0, 8, 16, 32, 64, 128 => return true, else => return false, }, .Fn => { @@ -24620,11 +24620,11 @@ fn validateExternType( .Packed => { const bit_size = try ty.bitSizeAdvanced(mod, sema); switch (bit_size) { - 8, 16, 32, 64, 128 => return true, + 0, 8, 16, 32, 64, 128 => return true, else => return false, } }, - .Auto => return false, + .Auto => return !(try sema.typeHasRuntimeBits(ty)), }, .Array => { if (position == .ret_ty or position == .param_ty) return false; @@ -24673,9 +24673,9 @@ fn explainWhyTypeIsNotExtern( .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) { - try mod.errNoteNonLazy(src_loc, msg, "only integers with power of two bits are extern compatible", .{}); + try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{}); } else { - try mod.errNoteNonLazy(src_loc, msg, "only integers with 8, 16, 32, 64 and 128 bits are extern compatible", .{}); + try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{}); }, .Fn => { if (position != .other) { |
