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: recognize enum constant named 'max...
details: https://anonhg.NetBSD.org/src/rev/30544e45da7c
branches: trunk
changeset: 372965:30544e45da7c
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 08 15:22:33 2023 +0000
description:
lint: recognize enum constant named 'max' as a count of values
Seen in external/bsd/mdocml/dist/mdoc.h(50).
diffstat:
tests/usr.bin/xlint/lint1/msg_348.c | 6 +-----
usr.bin/xlint/lint1/tree.c | 14 ++++++++------
2 files changed, 9 insertions(+), 11 deletions(-)
diffs (76 lines):
diff -r d3b890d37866 -r 30544e45da7c tests/usr.bin/xlint/lint1/msg_348.c
--- a/tests/usr.bin/xlint/lint1/msg_348.c Sun Jan 08 15:18:02 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_348.c Sun Jan 08 15:22:33 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_348.c,v 1.6 2023/01/08 15:18:02 rillig Exp $ */
+/* $NetBSD: msg_348.c,v 1.7 2023/01/08 15:22:33 rillig Exp $ */
# 3 "msg_348.c"
// Test for message 348: maximum value %d of '%s' does not match maximum array index %d [348]
@@ -177,7 +177,6 @@
enum uppercase_max {
M_FIRST,
M_SECOND,
- /* expect+1: previous declaration of 'M_MAX' [260] */
M_MAX
};
@@ -185,14 +184,12 @@
uppercase_max_name(enum uppercase_max x)
{
static const char *const name[] = { "first", "second" };
- /* expect+1: warning: maximum value 2 of 'enum uppercase_max' does not match maximum array index 1 [348] */
return name[x];
}
enum lowercase_max {
M_first,
M_second,
- /* expect+1: previous declaration of 'M_max' [260] */
M_max
};
@@ -200,6 +197,5 @@
lowercase_max_name(enum lowercase_max x)
{
static const char *const name[] = { "first", "second" };
- /* expect+1: warning: maximum value 2 of 'enum lowercase_max' does not match maximum array index 1 [348] */
return name[x];
}
diff -r d3b890d37866 -r 30544e45da7c usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jan 08 15:18:02 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jan 08 15:22:33 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.487 2023/01/08 15:22:33 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.487 2023/01/08 15:22:33 rillig Exp $");
#endif
#include <float.h>
@@ -2058,12 +2058,14 @@
return;
/*
- * If the largest enum constant is named '*_NUM_*', it is typically
- * not part of the allowed enum values but a marker for the number
- * of actual enum values.
+ * If the name of the largest enum constant contains 'MAX' or 'NUM',
+ * that constant is typically not part of the allowed enum values but
+ * a marker for the number of actual enum values.
*/
if (max_enum_value == max_array_index + 1 &&
- (strstr(max_ec->s_name, "NUM") != NULL ||
+ (strstr(max_ec->s_name, "MAX") != NULL ||
+ strstr(max_ec->s_name, "max") != NULL ||
+ strstr(max_ec->s_name, "NUM") != NULL ||
strstr(max_ec->s_name, "num") != NULL))
return;
Home |
Main Index |
Thread Index |
Old Index