diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index 6f275e0d3bd3d0..a895daf8a1cc7f 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -118,7 +118,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { is_dump_expr := expr is ast.DumpExpr is_var_mut := expr.is_auto_deref_var() str_fn_name := g.get_str_fn(exp_typ) - temp_var_needed := expr is ast.CallExpr && expr.return_type.is_ptr() + temp_var_needed := expr is ast.CallExpr + && (expr.return_type.is_ptr() || g.table.final_sym(expr.return_type).is_c_struct()) mut tmp_var := '' if temp_var_needed { tmp_var = g.new_tmp_var() diff --git a/vlib/v/tests/c_structs/csize.h b/vlib/v/tests/c_structs/csize.h new file mode 100644 index 00000000000000..01f605cf71079b --- /dev/null +++ b/vlib/v/tests/c_structs/csize.h @@ -0,0 +1,4 @@ +struct Size { + int width; + int height; +}; diff --git a/vlib/v/tests/c_structs/return_csize_test.v b/vlib/v/tests/c_structs/return_csize_test.v new file mode 100644 index 00000000000000..42917cd1f8c1c9 --- /dev/null +++ b/vlib/v/tests/c_structs/return_csize_test.v @@ -0,0 +1,15 @@ +#include "@VMODROOT/csize.h" + +struct C.Size { + width int + height int +} + +fn get_size() C.Size { + return C.Size{11, 22} +} + +fn test_return_csize() { + println(get_size()) + assert true +}