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 lint: add tests for 'constant in c...



details:   https://anonhg.NetBSD.org/src/rev/7bc27f7307c5
branches:  trunk
changeset: 980314:7bc27f7307c5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 31 12:29:16 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/msg_161.c   |  41 ++++++++++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_161.exp |   5 +++-
 2 files changed, 42 insertions(+), 4 deletions(-)

diffs (58 lines):

diff -r 6e1230a3320d -r 7bc27f7307c5 tests/usr.bin/xlint/lint1/msg_161.c
--- a/tests/usr.bin/xlint/lint1/msg_161.c       Sun Jan 31 12:20:00 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.c       Sun Jan 31 12:29:16 2021 +0000
@@ -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);
+}
diff -r 6e1230a3320d -r 7bc27f7307c5 tests/usr.bin/xlint/lint1/msg_161.exp
--- a/tests/usr.bin/xlint/lint1/msg_161.exp     Sun Jan 31 12:20:00 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.exp     Sun Jan 31 12:29:16 2021 +0000
@@ -1,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]



Home | Main Index | Thread Index | Old Index