1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix msvc struct init

This commit is contained in:
Alexander Medvednikov 2020-05-07 13:11:24 +02:00
parent 6ff93f270c
commit 12221fb999

View File

@ -2125,7 +2125,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
styp := g.typ(struct_init.typ) styp := g.typ(struct_init.typ)
is_amp := g.is_amp is_amp := g.is_amp
if is_amp { if is_amp {
g.out.go_back(1) // delete the & already generated in `prefix_expr() g.out.go_back(1) // delete the `&` already generated in `prefix_expr()
g.write('($styp*)memdup(&($styp){') g.write('($styp*)memdup(&($styp){')
} else { } else {
g.writeln('($styp){') g.writeln('($styp){')
@ -2151,8 +2151,10 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
g.writeln(',') g.writeln(',')
} }
// The rest of the fields are zeroed. // The rest of the fields are zeroed.
mut nr_info_fields := 0
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as table.Struct info := sym.info as table.Struct
nr_info_fields = info.fields.len
for field in info.fields { for field in info.fields {
if field.name in inited_fields { if field.name in inited_fields {
continue continue
@ -2170,9 +2172,10 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
} }
g.writeln(',') g.writeln(',')
} }
if struct_init.fields.len == 0 && info.fields.len == 0 {
g.write('0')
} }
// if struct_init.fields.len == 0 && info.fields.len == 0 {
if struct_init.fields.len == 0 && nr_info_fields == 0 {
g.write('0')
} }
g.write('}') g.write('}')
if is_amp { if is_amp {