shithub: scc

Download patch

ref: 8f1d626650ad8f6c77a6fdc12a8e49d35a7ca77e
parent: 0ee2df022f9a2b54b708960f23be30580b2b7c77
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jul 27 08:21:04 EDT 2015

Allow enum variables in switch expressions

enum variables have a different type, but they are integer
for everything, so they should be accepted in switches.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -217,9 +217,14 @@
 	expect(SWITCH);
 	expect ('(');
 	cond = expr();
-	if (BTYPE(cond) != INT)
+	switch (BTYPE(cond)) {
+	case INT:
+	case ENUM:
+		cond = convert(cond, inttype, 0);
+		break;
+	default:
 		error("incorrect type in switch statement");
-	cond = convert(cond, inttype, 0);
+	}
 	expect (')');
 
 	lbreak = newsym(NS_LABEL);