cgen: fix option struct default value init with -cstrict (spotted in #22783) (#22802)

This commit is contained in:
Felipe Pena 2024-11-08 12:01:44 -03:00 committed by GitHub
parent 80128f616e
commit bf83715b6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -107,7 +107,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
...node
typ: node.typ.clear_option_and_result()
})
g.writeln('}, &${tmp_var}, sizeof(${base_styp}));')
g.writeln('}, (${option_name}*)&${tmp_var}, sizeof(${base_styp}));')
g.empty_line = false
g.write2(s, tmp_var)
return

View File

@ -0,0 +1,16 @@
struct Element {
a int
}
@[noinit]
struct RawElement {
mut:
// tag Tag
content []u8
default_value ?Element
}
fn test_main() {
a := ?RawElement{}
dump(a)
}