Module Name: src
Committed By: rillig
Date: Thu Feb 27 22:37:37 UTC 2025
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_338.c
src/usr.bin/xlint/lint1: ckgetopt.c
Log Message:
lint: allow the getopt warning to be suppressed in the natural place
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_338.c
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/ckgetopt.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_338.c
diff -u src/tests/usr.bin/xlint/lint1/msg_338.c:1.9 src/tests/usr.bin/xlint/lint1/msg_338.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_338.c:1.9 Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_338.c Thu Feb 27 22:37:37 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_338.c,v 1.9 2023/03/28 14:44:35 rillig Exp $ */
+/* $NetBSD: msg_338.c,v 1.10 2025/02/27 22:37:37 rillig Exp $ */
# 3 "msg_338.c"
// Test for message: option '%c' should be handled in the switch [338]
@@ -156,3 +156,27 @@ unreachable_colon(int argc, char **argv)
}
return 0;
}
+
+void
+suppressed_warning(int argc, char **argv)
+{
+ int c;
+
+ /* expect+2: warning: option 'a' should be handled in the switch [338] */
+ /* expect+1: warning: option 'b' should be handled in the switch [338] */
+ while ((c = getopt(argc, argv, "ab")) != -1) {
+ switch (c) {
+ }
+ }
+ /* LINTED 338 */
+ while ((c = getopt(argc, argv, "ab")) != -1) {
+ switch (c) {
+ }
+ }
+ /* expect+2: warning: option 'a' should be handled in the switch [338] */
+ /* expect+1: warning: option 'b' should be handled in the switch [338] */
+ while ((c = getopt(argc, argv, "ab")) != -1) {
+ switch (c) {
+ }
+ }
+}
Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.27 src/usr.bin/xlint/lint1/ckgetopt.c:1.28
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.27 Tue Mar 19 23:19:03 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c Thu Feb 27 22:37:37 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.28 2025/02/27 22:37:37 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.28 2025/02/27 22:37:37 rillig Exp $");
#endif
#include <stdbool.h>
@@ -65,6 +65,7 @@ static struct {
* ':' should remain.
*/
pos_t options_pos;
+ int options_lwarn;
char *options;
/*
@@ -134,8 +135,11 @@ check_unhandled_option(void)
if (*opt == ' ' || *opt == ':')
continue;
+ int prev_lwarn = lwarn;
+ lwarn = ck.options_lwarn;
/* option '%c' should be handled in the switch */
warning_at(338, &ck.options_pos, *opt);
+ lwarn = prev_lwarn;
}
}
@@ -146,6 +150,7 @@ check_getopt_begin_while(const tnode_t *
if (ck.while_level == 0) {
if (!is_getopt_condition(tn, &ck.options))
return;
+ ck.options_lwarn = lwarn;
ck.options_pos = curr_pos;
}
ck.while_level++;