authorgravatar for 63465728+AliChraghi@users.noreply.github.comAli Chraghi <63465728+AliChraghi@users.noreply.github.com> 2021-12-28 08:03:11+03:30
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-12-27 23:33:11-05:00
log042b770d6272391a9c25f3444991b439ae07a1b5
tree79fce7488a46a9e11224a0ed051732fc42ec9f0b
parent6ed7850972c5d74912e6802474564de332ecf0d9
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std: Skip `comptime` struct fields in `mem.zeroes()` (#10406)

closes #9934

1 files changed, 6 insertions(+), 1 deletions(-)

lib/std/mem.zig+6-1
......@@ -275,7 +275,9 @@ pub fn zeroes(comptime T: type) T {
275275 } else {
276276 var structure: T = undefined;
277277 inline for (struct_info.fields) |field| {
278 @field(structure, field.name) = zeroes(@TypeOf(@field(structure, field.name)));
278 if (!field.is_comptime) {
279 @field(structure, field.name) = zeroes(@TypeOf(@field(structure, field.name)));
280 }
279281 }
280282 return structure;
281283 }
......@@ -342,6 +344,8 @@ test "mem.zeroes" {
342344 try testing.expect(a.y == 10);
343345
344346 const ZigStruct = struct {
347 comptime comptime_field: u8 = 5,
348
345349 integral_types: struct {
346350 integer_0: i0,
347351 integer_8: i8,
......@@ -376,6 +380,7 @@ test "mem.zeroes" {
376380 };
377381
378382 const b = zeroes(ZigStruct);
383 try testing.expectEqual(@as(u8, 5), b.comptime_field);
379384 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
380385 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
381386 try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);