We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44c321c commit 18440cbCopy full SHA for 18440cb
lib/std/mem.zig
@@ -267,7 +267,7 @@ pub fn zeroes(comptime T: type) T {
267
return null;
268
},
269
.Struct => |struct_info| {
270
- if (@sizeOf(T) == 0) return T{};
+ if (@sizeOf(T) == 0) return undefined;
271
if (struct_info.layout == .Extern) {
272
var item: T = undefined;
273
set(u8, asBytes(&item), 0);
@@ -424,6 +424,9 @@ test "zeroes" {
424
425
comptime var comptime_union = zeroes(C_union);
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 });
430
}
431
432
/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
0 commit comments