Module Name: src
Committed By: rillig
Date: Wed Mar 10 00:02:00 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_130.c msg_130.exp
src/usr.bin/xlint/lint1: func.c
Log Message:
lint: disable check for enum type mismatch in switch statement
This check has been too quick and broke the lint build. Among others,
lib/libpuffs has -w included in LINTFLAGS, which means that the build
can fail even for new warnings, not only for errors.
libpuffs compares a uint16_t with constants from an unnamed enum type.
Since the enum type is completely unnamed (neither a tag nor a typedef),
there is no way to define a struct member having this type. This was a
scenario that I just didn't consider when I added the check to lint.
For now, disable the new check completely. The previously existing lint
checks stay enabled, including the one that warns about mismatched
anonymous enum types in the '==' operator, which is very similar to the
now disabled check.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_130.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_130.exp
cvs rdiff -u -r1.75 -r1.76 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_130.c
diff -u src/tests/usr.bin/xlint/lint1/msg_130.c:1.10 src/tests/usr.bin/xlint/lint1/msg_130.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_130.c:1.10 Tue Mar 9 23:40:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.c Wed Mar 10 00:02:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_130.c,v 1.10 2021/03/09 23:40:43 rillig Exp $ */
+/* $NetBSD: msg_130.c,v 1.11 2021/03/10 00:02:00 rillig Exp $ */
# 3 "msg_130.c"
// Test for message: enum type mismatch: '%s' '%s' '%s' [130]
@@ -44,9 +44,9 @@ void
switch_example(enum color c)
{
switch (c) {
- case EVENING: /* expect: 130 */
- case LARGE: /* expect: 130 */
- case 0: /* expect: 130 */
+ case EVENING: /* maybe someday expect: 130 */
+ case LARGE: /* maybe someday expect: 130 */
+ case 0: /* maybe someday expect: 130 */
sink(1 == 1);
break;
default:
@@ -71,10 +71,11 @@ enum {
int
enum_constant_from_unnamed_type(int x)
{
+ /* using an enum constant as constant-expression */
switch (x) {
- case sizeof_int: /* expect: 130 *//* FIXME */
+ case sizeof_int:
return 1;
- case sizeof_long: /* expect: 130 *//* FIXME */
+ case sizeof_long:
return 2;
default:
break;
Index: src/tests/usr.bin/xlint/lint1/msg_130.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_130.exp:1.8 src/tests/usr.bin/xlint/lint1/msg_130.exp:1.9
--- src/tests/usr.bin/xlint/lint1/msg_130.exp:1.8 Tue Mar 9 23:40:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.exp Wed Mar 10 00:02:00 2021
@@ -1,10 +1,5 @@
msg_130.c(29): warning: enum type mismatch: 'enum color' ':' 'enum daytime' [130]
msg_130.c(31): warning: enum type mismatch: 'enum color' '!=' 'enum size' [130]
msg_130.c(32): warning: enum type mismatch: 'enum color' '==' 'enum size' [130]
-msg_130.c(47): warning: enum type mismatch: 'enum color' '==' 'enum daytime' [130]
-msg_130.c(48): warning: enum type mismatch: 'enum color' '==' 'enum size' [130]
-msg_130.c(49): warning: enum type mismatch: 'enum color' '==' 'int' [130]
-msg_130.c(75): warning: enum type mismatch: 'int' '==' 'enum <unnamed>' [130]
-msg_130.c(77): warning: enum type mismatch: 'int' '==' 'enum <unnamed>' [130]
-msg_130.c(88): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]
-msg_130.c(126): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]
+msg_130.c(89): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]
+msg_130.c(127): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.75 src/usr.bin/xlint/lint1/func.c:1.76
--- src/usr.bin/xlint/lint1/func.c:1.75 Fri Mar 5 17:10:05 2021
+++ src/usr.bin/xlint/lint1/func.c Wed Mar 10 00:02:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.75 2021/03/05 17:10:05 rillig Exp $ */
+/* $NetBSD: func.c,v 1.76 2021/03/10 00:02:00 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.75 2021/03/05 17:10:05 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.76 2021/03/10 00:02:00 rillig Exp $");
#endif
#include <stdlib.h>
@@ -437,9 +437,11 @@ check_case_label_enum(const tnode_t *tn,
tn->tn_type->t_enum == ci->c_swtype->t_enum)
return;
+#if 0 /* not yet ready, see msg_130.c */
/* enum type mismatch: '%s' '%s' '%s' */
warning(130, type_name(ci->c_swtype), getopname(EQ),
type_name(tn->tn_type));
+#endif
}
static void