Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix wrong warning about unhandled ...



details:   https://anonhg.NetBSD.org/src/rev/4966587ea3a5
branches:  trunk
changeset: 366350:4966587ea3a5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 22 13:58:59 2022 +0000

description:
lint: fix wrong warning about unhandled enum constants in switch

diffstat:

 tests/usr.bin/xlint/lint1/msg_206.c   |  10 +++++++---
 tests/usr.bin/xlint/lint1/msg_206.exp |   1 -
 usr.bin/xlint/lint1/func.c            |   6 +++---
 3 files changed, 10 insertions(+), 7 deletions(-)

diffs (56 lines):

diff -r 2b2d09b492ac -r 4966587ea3a5 tests/usr.bin/xlint/lint1/msg_206.c
--- a/tests/usr.bin/xlint/lint1/msg_206.c       Sun May 22 13:53:39 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_206.c       Sun May 22 13:58:59 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_206.c,v 1.5 2022/05/22 13:53:39 rillig Exp $       */
+/*     $NetBSD: msg_206.c,v 1.6 2022/05/22 13:58:59 rillig Exp $       */
 # 3 "msg_206.c"
 
 // Test for message: enumeration value(s) not handled in switch [206]
@@ -40,7 +40,11 @@
        case 3:
                return -1;
        }
-       /* FIXME: There are _too many_ branches, not _too few_. */
-       /* expect-2: warning: enumeration value(s) not handled in switch [206] */
+       /*
+        * Before func.c 1.137 from 2022-05-22, lint complained that there
+        * were enum constants not handled in switch, even though all of them
+        * are handled.  The code smell in this case is that there are _too
+        * many_ branches that cover "impossible" values.
+        */
        return 3;
 }
diff -r 2b2d09b492ac -r 4966587ea3a5 tests/usr.bin/xlint/lint1/msg_206.exp
--- a/tests/usr.bin/xlint/lint1/msg_206.exp     Sun May 22 13:53:39 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_206.exp     Sun May 22 13:58:59 2022 +0000
@@ -1,2 +1,1 @@
 msg_206.c(19): warning: enumeration value(s) not handled in switch [206]
-msg_206.c(42): warning: enumeration value(s) not handled in switch [206]
diff -r 2b2d09b492ac -r 4966587ea3a5 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun May 22 13:53:39 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun May 22 13:58:59 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.136 2022/05/20 21:18:55 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.137 2022/05/22 13:58:59 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.136 2022/05/20 21:18:55 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.137 2022/05/22 13:58:59 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -760,7 +760,7 @@
                }
                for (cl = cstmt->c_case_labels; cl != NULL; cl = cl->cl_next)
                        nclab++;
-               if (hflag && eflag && nenum != nclab && !cstmt->c_default) {
+               if (hflag && eflag && nclab < nenum && !cstmt->c_default) {
                        /* enumeration value(s) not handled in switch */
                        warning(206);
                }



Home | Main Index | Thread Index | Old Index