scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 8f1d626650ad8f6c77a6fdc12a8e49d35a7ca77e
parent 0ee2df022f9a2b54b708960f23be30580b2b7c77
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Jul 2015 12:21:04 +0200

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.

Diffstat:
Mcc1/stmt.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -217,9 +217,14 @@ Switch(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) 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);