Prefer compiler warnings to assertions for unhandled switch cases

Using 'default:' cases can hide logical errors which would lead to i3
crashes for users. With this change the compiler will print a warning
when a case is not handled. For example, if I add a new value in the
Font.type enum:
../../i3/libi3/font.c: In function ‘draw_text’:
../../i3/libi3/font.c:378:5: warning: enumeration value ‘NEWFONT’ not handled in switch [-Wswitch]
     switch (savedFont->type) {
     ^~~~~~
This commit is contained in:
Orestis Floros
2018-04-04 18:12:44 +03:00
parent 393412a204
commit 0aa636b207
4 changed files with 5 additions and 28 deletions

View File

@ -268,10 +268,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
case CT_DOCKAREA:
ystr("dockarea");
break;
default:
DLOG("About to dump unknown container type=%d. This is a bug.\n", con->type);
assert(false);
break;
}
/* provided for backwards compatibility only. */