gcc (GCC) 4.0.0 20041121 (experimental) -Wswitch-enum generates the warning even if the range in case expression covers all possible values of a enum. The first value of the range (a0 in the example below) is not listed as missing (but all others, including the last). The generated code works properly, though. Example: enum a { a0, a1, a2, a3 }; int error(enum a aa) { switch ( aa ) { case a0 ... a3: return 1; } return 0; } Output: gcc4-enum.c: In function 'error': gcc4-enum.c:5: warning: enumeration value 'a1' not handled in switch gcc4-enum.c:5: warning: enumeration value 'a2' not handled in switch gcc4-enum.c:5: warning: enumeration value 'a3' not handled in switch GCC (from gcc-4.0-20041121 snapshot) configured and compiled: ../gcc-4.0-20041121/configure --enable-threads --with-tune=pentium4 --disable-nls --enable-languages=c,c++ (removing -mtune=pentium4 didn't help)
: Search converges between 2004-05-11-trunk (#454) and 2004-05-14-trunk (#455). : Search converges between 2003-10-30-ssa (#120) and 2003-10-31-ssa (#121). Confirmed, a regression.
This patch caused it, the moving to the front-end must had forgot about some detail: 2003-10-30 Richard Henderson <rth@redhat.com> * c-common.c (match_case_to_enum_1, match_case_to_enum): New. (c_do_switch_warnings): New.
Created attachment 7735 [details] Patch which fixes the problem I am testing this fix, I copied the code from c_add_case_label and changed it a little bit.
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01028.html>.
*** Bug 20571 has been marked as a duplicate of this bug. ***
Is there a more recent patch version than that referred to in comment #4, taking account of Mark's comments on that patch version?
(In reply to comment #6) > Is there a more recent patch version than that referred to in comment #4, > taking account of Mark's comments on that patch version? I was talking with Roger off the list and he said Mark was wrong in that and also this code was just copied from exactly from c_add_case_label. I am going to apply the patch as is, in the next couple days.
Removing rejects-valid; treating all incorrect warnings as rejects-valid due to -Werror is not useful.
Subject: Bug 18715 CVSROOT: /cvs/gcc Module name: gcc Changes by: pinskia@gcc.gnu.org 2005-08-22 16:21:19 Modified files: gcc : ChangeLog c-common.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: switch-warn-3.c Log message: 2005-08-22 Andrew Pinski <pinskia@physics.uc.edu> PR c/18715 * c-common.c (c_do_switch_warnings): Look for a node where the enum's value is inbetween the range if we did not find an exact match. 2005-08-22 Andrew Pinski <pinskia@physics.uc.edu> PR c/18175 * gcc.dg/switch-warn-3.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9798&r2=2.9799 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.649&r2=1.650 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5947&r2=1.5948 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/switch-warn-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 18715 CVSROOT: /cvs/gcc Module name: gcc Changes by: pinskia@gcc.gnu.org 2005-08-22 16:26:06 Modified files: gcc/testsuite : ChangeLog Log message: Fix PR number in changelog: 2005-08-22 Andrew Pinski <pinskia@physics.uc.edu> PR c/18715 * gcc.dg/switch-warn-3.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5948&r2=1.5949
Fixed.
Subject: Bug 18715 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: pinskia@gcc.gnu.org 2005-08-22 16:29:02 Modified files: gcc : ChangeLog c-common.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: switch-warn-3.c Log message: 2005-08-22 Andrew Pinski <pinskia@physics.uc.edu> PR c/18715 * c-common.c (c_do_switch_warnings): Look for a node where the enum's value is inbetween the range if we did not find an exact match. 2005-08-22 Andrew Pinski <pinskia@physics.uc.edu> PR c/18715 * gcc.dg/switch-warn-3.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.381&r2=2.7592.2.382 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.606.2.6&r2=1.606.2.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.344&r2=1.5084.2.345 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/switch-warn-3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1