[hackers] [scc] Allow enum variables in switch expressions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 27 Jul 2015 17:09:31 +0200 (CEST)

commit 8f1d626650ad8f6c77a6fdc12a8e49d35a7ca77e
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jul 27 12:21:04 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jul 27 12:21:04 2015 +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.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index 5c48686..7f75108 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -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);
Received on Mon Jul 27 2015 - 17:09:31 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 27 2015 - 17:12:16 CEST