Module Name: src Committed By: rillig Date: Sun May 22 13:58:59 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: msg_206.c msg_206.exp src/usr.bin/xlint/lint1: func.c Log Message: lint: fix wrong warning about unhandled enum constants in switch To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_206.c \ src/tests/usr.bin/xlint/lint1/msg_206.exp cvs rdiff -u -r1.136 -r1.137 src/usr.bin/xlint/lint1/func.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_206.c diff -u src/tests/usr.bin/xlint/lint1/msg_206.c:1.5 src/tests/usr.bin/xlint/lint1/msg_206.c:1.6 --- src/tests/usr.bin/xlint/lint1/msg_206.c:1.5 Sun May 22 13:53:39 2022 +++ src/tests/usr.bin/xlint/lint1/msg_206.c Sun May 22 13:58:59 2022 @@ -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 @@ too_many(enum number num) 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; } Index: src/tests/usr.bin/xlint/lint1/msg_206.exp diff -u src/tests/usr.bin/xlint/lint1/msg_206.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_206.exp:1.6 --- src/tests/usr.bin/xlint/lint1/msg_206.exp:1.5 Sun May 22 13:53:39 2022 +++ src/tests/usr.bin/xlint/lint1/msg_206.exp Sun May 22 13:58:59 2022 @@ -1,2 +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] Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.136 src/usr.bin/xlint/lint1/func.c:1.137 --- src/usr.bin/xlint/lint1/func.c:1.136 Fri May 20 21:18:55 2022 +++ src/usr.bin/xlint/lint1/func.c Sun May 22 13:58:59 2022 @@ -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 @@ switch2(void) } 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); }