From 12221fb99937c30d80d6f00a04ad772de7f1844f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 7 May 2020 13:11:24 +0200 Subject: [PATCH] cgen: fix msvc struct init --- vlib/v/gen/cgen.v | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index aa972c36a8..f377029f2e 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2125,7 +2125,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { styp := g.typ(struct_init.typ) is_amp := g.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){') } else { g.writeln('($styp){') @@ -2151,8 +2151,10 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { g.writeln(',') } // The rest of the fields are zeroed. + mut nr_info_fields := 0 if sym.kind == .struct_ { info := sym.info as table.Struct + nr_info_fields = info.fields.len for field in info.fields { if field.name in inited_fields { continue @@ -2170,9 +2172,10 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { } 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('}') if is_amp {