Skip to content

Commit

Permalink
Initialize first field in named union constructors
Browse files Browse the repository at this point in the history
This allows job_spec_data fields embedded in other types to be initialized to -1 as expected
  • Loading branch information
lethosor committed Jun 15, 2024
1 parent dd88a9b commit 17e4c6d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion StructFields.pm
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,13 @@ sub emit_struct_fields($$;%) {
} 'fields-' . $fields_group;

# Needed for unions with fields with non-default ctors (e.g. bitfields)
emit "$name(){memset(this, 0, sizeof($name));}";
emit_block {
local $in_union = 1;
emit "memset(this, 0, sizeof(*this));";
# for unions with fields defined, initialize the first one
my $first_child = ($tag->findnodes('ld:field[1]'))[0];
render_field_init($first_child);
} "$name() ";

return;
}
Expand Down

0 comments on commit 17e4c6d

Please sign in to comment.