| ... | ... | @@ -267,7 +267,7 @@ pub fn zeroes(comptime T: type) T { |
| 267 | 267 | return null; |
| 268 | 268 | }, |
| 269 | 269 | .Struct => |struct_info| { |
| 270 | | if (@sizeOf(T) == 0) return T{}; |
| 270 | if (@sizeOf(T) == 0) return undefined; |
| 271 | 271 | if (struct_info.layout == .Extern) { |
| 272 | 272 | var item: T = undefined; |
| 273 | 273 | set(u8, asBytes(&item), 0); |
| ... | ... | @@ -424,6 +424,9 @@ test "zeroes" { |
| 424 | 424 | |
| 425 | 425 | comptime var comptime_union = zeroes(C_union); |
| 426 | 426 | try testing.expectEqual(@as(u8, 0), comptime_union.a); |
| 427 | |
| 428 | // Ensure zero sized struct with fields is initialized correctly. |
| 429 | _ = zeroes(struct { handle: void }); |
| 427 | 430 | } |
| 428 | 431 | |
| 429 | 432 | /// Initializes all fields of the struct with their default value, or zero values if no default value is present. |