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: document why accidenta...



details:   https://anonhg.NetBSD.org/src/rev/6b5405510356
branches:  trunk
changeset: 359671:6b5405510356
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 16 10:11:38 2022 +0000

description:
tests/lint: document why accidental double semicolons are hard to detect

diffstat:

 tests/usr.bin/xlint/lint1/msg_193.c   |  23 ++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_193.exp |   2 +-
 2 files changed, 23 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r c0703d104cab -r 6b5405510356 tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Sun Jan 16 09:41:28 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Sun Jan 16 10:11:38 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_193.c,v 1.16 2022/01/15 23:21:34 rillig Exp $      */
+/*     $NetBSD: msg_193.c,v 1.17 2022/01/16 10:11:38 rillig Exp $      */
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -672,6 +672,27 @@
        ;;
 
        /*
+        * If assertions are disabled with -DNDEBUG and __lint__ is defined,
+        * NetBSD's <assert.h> defines assert(x) to nothing, leaving only
+        * the trailing semicolon.  If there are several assertions next to
+        * each other, without any whitespace in between (very unusual), the
+        * GCC preprocessor generates ";;" for them, which makes them
+        * indistinguishable from the literal ";;" from the typo above.
+        *
+        * (echo '#include <assert.h>'; echo 'assert(0);assert(1);') \
+        * | gcc -DNDEBUG -E - -D__lint__
+        *
+        * To actually see the difference, lint would need to look at the
+        * code before preprocessing and compare it with the preprocessed
+        * code, which would be a lot of work.
+        *
+        * Apart from the above edge case, detecting extra semicolons would
+        * be possible, but lint would have to look at the whitespace between
+        * the tokens, and this is something that it doesn't do at all, as of
+        * 2022-01-16.
+        */
+
+       /*
         * A stand-alone null statement, on the other hand, has its purpose.
         * Without it, the 'for' loop would not be complete.  The NetBSD
         * style is to use 'continue;' instead of a simple ';'.
diff -r c0703d104cab -r 6b5405510356 tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Jan 16 09:41:28 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Jan 16 10:11:38 2022 +0000
@@ -87,4 +87,4 @@
 msg_193.c(606): warning: statement not reached [193]
 msg_193.c(627): warning: statement not reached [193]
 msg_193.c(655): warning: statement not reached [193]
-msg_193.c(683): warning: statement not reached [193]
+msg_193.c(704): warning: statement not reached [193]



Home | Main Index | Thread Index | Old Index