Skip to content

Commit 4f773fc

Browse files
authored
cgen: improve codegen for array fixed init for g++ compiler (fix #25723) (#25725)
1 parent 32be855 commit 4f773fc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

vlib/v/gen/c/comptime.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,16 @@ fn (mut g Gen) comptime_if(node ast.IfExpr) {
492492
g.writeln('builtin___result_ok(&(${base_styp}[]) { ${tmp_var2} }, (_result*)(&${tmp_var}), sizeof(${base_styp}));')
493493
g.writeln('}')
494494
} else if is_array_fixed {
495+
tmp_var2 := g.new_tmp_var()
495496
base_styp := g.base_type(node.typ)
496-
g.write('memcpy(&${tmp_var}, (${base_styp})')
497+
g.write('{ ${base_styp} ${tmp_var2} = ')
497498
g.stmt(last)
498499
if g.out.last_n(2).contains(';') {
499500
g.go_back(2)
500501
}
501-
g.write(', sizeof(${base_styp}))')
502+
g.writeln(';')
503+
g.writeln2('memcpy(&${tmp_var}, &${tmp_var2}, sizeof(${base_styp}));',
504+
'}')
502505
} else {
503506
g.write('${tmp_var} = ')
504507
g.stmt(last)

0 commit comments

Comments
 (0)