Module Name: src
Committed By: rillig
Date: Sun Jan 31 12:29:16 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_161.c msg_161.exp
Log Message:
lint: add tests for 'constant in conditional context'
One of these tests explains why 'do { } while (0)' is so usual that
there is no reason to warn about it. That warning will not survive for
long.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_161.c \
src/tests/usr.bin/xlint/lint1/msg_161.exp
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_161.c
diff -u src/tests/usr.bin/xlint/lint1/msg_161.c:1.1 src/tests/usr.bin/xlint/lint1/msg_161.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_161.c:1.1 Sat Jan 2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_161.c Sun Jan 31 12:29:16 2021
@@ -1,7 +1,42 @@
-/* $NetBSD: msg_161.c,v 1.1 2021/01/02 10:22:43 rillig Exp $ */
+/* $NetBSD: msg_161.c,v 1.2 2021/01/31 12:29:16 rillig Exp $ */
# 3 "msg_161.c"
// Test for message: constant in conditional context [161]
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -h */
+
+void
+while_1(void)
+{
+ while (1)
+ continue;
+}
+
+void
+while_0(void)
+{
+ while (0)
+ continue;
+}
+
+/*
+ * The pattern 'do { } while (0)' is a common technique to define a
+ * preprocessor macro that behaves like a single statement. There is
+ * nothing unusual or surprising about the constant condition.
+ * Still, lint warns about it. FIXME don't.
+ */
+void
+do_while_0(void)
+{
+ do {
+
+ } while (0);
+}
+
+void
+do_while_1(void)
+{
+ do {
+
+ } while (1);
+}
Index: src/tests/usr.bin/xlint/lint1/msg_161.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_161.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_161.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_161.exp:1.1 Sat Jan 2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_161.exp Sun Jan 31 12:29:16 2021
@@ -1 +1,4 @@
-msg_161.c(6): syntax error ':' [249]
+msg_161.c(11): warning: constant in conditional context [161]
+msg_161.c(18): warning: constant in conditional context [161]
+msg_161.c(33): warning: constant in conditional context [161]
+msg_161.c(41): warning: constant in conditional context [161]