Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5891,14 +5891,17 @@ static void doswitch(void)
int swdefault,casecount;
int tok,endtok;
int swtag,csetag;
int ident;
cell val;
char *str;
constvalue_root caselist = { NULL, NULL}; /* case list starts empty */
constvalue *cse,*csp,*newval;
char labelname[sNAMEMAX+1];

endtok= matchtoken('(') ? ')' : tDO;
doexpr(TRUE,FALSE,FALSE,FALSE,&swtag,NULL,TRUE,NULL);/* evaluate switch expression */
ident=doexpr(TRUE,FALSE,FALSE,FALSE,&swtag,NULL,TRUE,NULL); /* evaluate switch expression */
if (ident==iCONSTEXPR)
error(241); /* redundant code: switch control expression is constant */
needtoken(endtok);
/* generate the code for the switch statement, the label is the address
* of the case table (to be generated later).
Expand Down
3 changes: 2 additions & 1 deletion source/compiler/sc5.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ static char *warnmsg[] = {
/*237*/ "user warning: %s\n",
/*238*/ "meaningless combination of class specifiers (%s)\n",
/*239*/ "literal array/string passed to a non-const parameter\n",
/*240*/ "previously assigned value is never used (symbol \"%s\")\n"
/*240*/ "previously assigned value is never used (symbol \"%s\")\n",
/*241*/ "redundant code: switch control expression is constant\n"
};

static char *noticemsg[] = {
Expand Down
8 changes: 8 additions & 0 deletions source/compiler/tests/warning_241.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'test_type': 'output_check',
'errors': """
warning_241.pwn(6) : warning 241: redundant code: switch control expression is constant
warning_241.pwn(7) : warning 241: redundant code: switch control expression is constant
warning_241.pwn(8) : warning 241: redundant code: switch control expression is constant
"""
}
10 changes: 10 additions & 0 deletions source/compiler/tests/warning_241.pwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
main()
{
const CONST_1 = 1;
new var = 0;

switch (0) {} // warning 241
switch (CONST_1) {} // warning 241
switch (CONST_1 + 1) {} // warning 241
switch (var) {}
}