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: add more examples for ...



details:   https://anonhg.NetBSD.org/src/rev/b39fb4dd4d78
branches:  trunk
changeset: 1024110:b39fb4dd4d78
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 10 09:17:24 2021 +0000

description:
tests/lint: add more examples for continue in do-while-0

diffstat:

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

diffs (67 lines):

diff -r 2f241e7d224f -r b39fb4dd4d78 tests/usr.bin/xlint/lint1/msg_323.c
--- a/tests/usr.bin/xlint/lint1/msg_323.c       Sun Oct 10 08:59:45 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_323.c       Sun Oct 10 09:17:24 2021 +0000
@@ -1,11 +1,35 @@
-/*     $NetBSD: msg_323.c,v 1.3 2021/10/09 21:25:39 rillig Exp $       */
+/*     $NetBSD: msg_323.c,v 1.4 2021/10/10 09:17:24 rillig Exp $       */
 # 3 "msg_323.c"
 
 // Test for message: continue in 'do ... while (0)' loop [323]
+
 void println(const char *);
 
+/*
+ * In simple cases of a do-while-0 loop, the statements 'break' and
+ * 'continue' have the same effect, and 'break' is much more common.
+ *
+ * This is also covered by Clang-Tidy.
+ */
 void
-example(const char *p)
+simple_case(const char *p)
+{
+       do {
+               if (p[0] == '+')
+                       break;
+               if (p[1] == '-')
+                       continue;
+               println("no sign");
+       /* expect+1: error: continue in 'do ... while (0)' loop [323] */
+       } while (0);
+}
+
+/*
+ * If there is a 'switch' statement inside the do-while-0 loop, the 'break'
+ * statement is tied to the 'switch' statement instead of the loop.
+ */
+void
+nested_switch(const char *p)
 {
        do {
                switch (*p) {
@@ -19,3 +43,18 @@
        /* expect+1: error: continue in 'do ... while (0)' loop [323] */
        } while (0);
 }
+
+/*
+ * In a nested loop, the 'continue' statement is bound to the inner loop,
+ * thus no warning.
+ */
+void
+nested_for(void)
+{
+       do {
+               for (int i = 0; i < 6; i++) {
+                       if (i < 3)
+                               continue;
+               }
+       } while (0);
+}
diff -r 2f241e7d224f -r b39fb4dd4d78 tests/usr.bin/xlint/lint1/msg_323.exp
--- a/tests/usr.bin/xlint/lint1/msg_323.exp     Sun Oct 10 08:59:45 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_323.exp     Sun Oct 10 09:17:24 2021 +0000
@@ -1,1 +1,2 @@
-msg_323.c(20): error: continue in 'do ... while (0)' loop [323]
+msg_323.c(24): error: continue in 'do ... while (0)' loop [323]
+msg_323.c(44): error: continue in 'do ... while (0)' loop [323]



Home | Main Index | Thread Index | Old Index