[vala] Generate dummy return statement to avoid C warning
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Generate dummy return statement to avoid C warning
- Date: Mon, 22 Mar 2010 22:00:49 +0000 (UTC)
commit e37a70819b26a5dd5d664c26bf9d27f48e608484
Author: Jürg Billeter <j bitron ch>
Date: Mon Mar 22 22:58:08 2010 +0100
Generate dummy return statement to avoid C warning
codegen/valaccodemethodmodule.vala | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 35257f1..605ce8e 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -564,11 +564,15 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
}
if (!(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) {
- // do not declare result variable if exit block is known to be unreachable
- if (m.exit_block == null || m.exit_block.get_predecessors ().size > 0) {
- var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
- cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
- cinit.append (cdecl);
+ var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
+ var vardecl = new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true));
+ vardecl.init0 = true;
+ cdecl.add_declarator (vardecl);
+ cinit.append (cdecl);
+
+ // add dummy return if exit block is known to be unreachable to silence C compiler
+ if (m.exit_block != null && m.exit_block.get_predecessors ().size == 0) {
+ function.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]