Bug 18715 - [4.0/4.1 Regression] warning: "enumeration value not handled in switch" for '...' ranges
Summary: [4.0/4.1 Regression] warning: "enumeration value not handled in switch" for '...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Andrew Pinski
URL:
Keywords: diagnostic, patch
: 20571 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-11-29 11:58 UTC by fork0
Modified: 2005-08-22 16:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-01-28 06:31:51


Attachments
Patch which fixes the problem (978 bytes, patch)
2004-12-14 06:31 UTC, Andrew Pinski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description fork0 2004-11-29 11:58:38 UTC
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)
Comment 1 Andrew Pinski 2004-11-29 12:52:13 UTC
: 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.
Comment 2 Andrew Pinski 2004-12-14 06:01:55 UTC
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.
Comment 3 Andrew Pinski 2004-12-14 06:31:37 UTC
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.
Comment 4 Andrew Pinski 2004-12-14 14:34:52 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01028.html>.
Comment 5 Andrew Pinski 2005-03-20 23:34:40 UTC
*** Bug 20571 has been marked as a duplicate of this bug. ***
Comment 6 Joseph S. Myers 2005-03-30 18:09:54 UTC
Is there a more recent patch version than that referred to in comment #4,
taking account of Mark's comments on that patch version?
Comment 7 Andrew Pinski 2005-04-05 01:42:03 UTC
(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.
Comment 8 Mark Mitchell 2005-04-08 21:48:03 UTC
Removing rejects-valid; treating all incorrect warnings as rejects-valid due to
-Werror is not useful.
Comment 9 GCC Commits 2005-08-22 16:21:37 UTC
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

Comment 10 GCC Commits 2005-08-22 16:26:15 UTC
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

Comment 11 Andrew Pinski 2005-08-22 16:28:05 UTC
Fixed.
Comment 12 GCC Commits 2005-08-22 16:29:12 UTC
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