[vala] codegen: Always add default label to switch statements



commit 375432cb2bc46e53c7323469dc3ddd838ace5c7c
Author: Jürg Billeter <j bitron ch>
Date:   Thu Jan 13 07:19:32 2011 +0100

    codegen: Always add default label to switch statements

 codegen/valaccodecontrolflowmodule.vala |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index 6e7ac13..30bb83d 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -172,13 +172,22 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
 
 		ccode.open_switch (get_cvalue (stmt.expression));
 
+		bool has_default = false;
+
 		foreach (SwitchSection section in stmt.get_sections ()) {
 			if (section.has_default_label ()) {
 				ccode.add_default ();
+				has_default = true;
 			}
 			section.emit (this);
 		}
 
+		if (!has_default) {
+			// silence C compiler
+			ccode.add_default ();
+			ccode.add_break ();
+		}
+
 		ccode.close ();
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]