summaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authorMichael James Gratton <mike@vee.net>2017-02-06 16:47:21 +1100
committerRico Tzschichholz <ricotz@ubuntu.com>2017-02-08 11:23:28 +0100
commitc73d19cc1d9919dcdf992fe0263f108c86dd328a (patch)
tree69746eebb0a66ab6b7a75474fcd0cca5d1072c2e /codegen
parent6b275cf3adcdae1b91054586435d10c99d13c0ef (diff)
downloadvala-c73d19cc1d9919dcdf992fe0263f108c86dd328a.tar.gz
codegen: Don't return void for non-nullable simple-type structs
https://bugzilla.gnome.org/show_bug.cgi?id=778224
Diffstat (limited to 'codegen')
-rw-r--r--codegen/valaccodebasemodule.vala11
1 files changed, 10 insertions, 1 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9a046908b..f979dab46 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6529,7 +6529,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public void return_default_value (DataType return_type) {
- ccode.add_return (default_value_for_type (return_type, false));
+ var st = return_type.data_type as Struct;
+ if (st != null && st.is_simple_type () && !return_type.nullable) {
+ // 0-initialize struct with struct initializer { 0 }
+ // only allowed as initializer expression in C
+ var ret_temp_var = get_temp_variable (return_type, true, null, true);
+ emit_temp_var (ret_temp_var);
+ ccode.add_return (new CCodeIdentifier (ret_temp_var.name));
+ } else {
+ ccode.add_return (default_value_for_type (return_type, false));
+ }
}
public virtual void generate_dynamic_method_wrapper (DynamicMethod method) {