Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add test for incompati...
details: https://anonhg.NetBSD.org/src/rev/0f4a67df79a1
branches: trunk
changeset: 960019:0f4a67df79a1
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Mar 05 16:31:49 2021 +0000
description:
tests/lint: add test for incompatible enums in switch
Neither lint nor GCC 10 nor Clang 8 have a warning for an enum type
mismatch in a switch statement.
GCC 10 issues a warning but completely misses the point of the
mismatched enum types. It only warns because in this test, EVENING has
the numeric value 3, which is out of bounds for enum color, where the
valid range is from 0 to 2. It says:
> msg_130.c:45:2: warning:
> case value ‘3’ not in enumerated type ‘enum color’ [-Wswitch]
Clang 8 behaves almost the same, it just doesn't mention the value of
the constant, saying merely 'case value not in enumerated type'.
diffstat:
tests/usr.bin/xlint/lint1/msg_130.c | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diffs (26 lines):
diff -r dd2e619b5c40 -r 0f4a67df79a1 tests/usr.bin/xlint/lint1/msg_130.c
--- a/tests/usr.bin/xlint/lint1/msg_130.c Fri Mar 05 13:21:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_130.c Fri Mar 05 16:31:49 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_130.c,v 1.5 2021/02/28 01:30:22 rillig Exp $ */
+/* $NetBSD: msg_130.c,v 1.6 2021/03/05 16:31:49 rillig Exp $ */
# 3 "msg_130.c"
// Test for message: enum type mismatch: '%s' '%s' '%s' [130]
@@ -37,3 +37,16 @@
/* The cast to unsigned is required by GCC at WARNS=6. */
c &= ~(unsigned)MEDIUM; /* might be useful to warn about */
}
+
+void
+switch_example(enum color c)
+{
+ switch (c) {
+ case EVENING: /* TODO: 130 */
+ case LARGE: /* TODO: 130 */
+ sink(1 == 1);
+ break;
+ default:
+ break;
+ }
+}
Home |
Main Index |
Thread Index |
Old Index