Module Name: src
Committed By: rillig
Date: Sun Oct 10 09:17:25 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_323.c msg_323.exp
Log Message:
tests/lint: add more examples for continue in do-while-0
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_323.c \
src/tests/usr.bin/xlint/lint1/msg_323.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_323.c
diff -u src/tests/usr.bin/xlint/lint1/msg_323.c:1.3 src/tests/usr.bin/xlint/lint1/msg_323.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_323.c:1.3 Sat Oct 9 21:25:39 2021
+++ src/tests/usr.bin/xlint/lint1/msg_323.c Sun Oct 10 09:17:24 2021
@@ -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
+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
-example(const char *p)
+nested_switch(const char *p)
{
do {
switch (*p) {
@@ -19,3 +43,18 @@ example(const char *p)
/* 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);
+}
Index: src/tests/usr.bin/xlint/lint1/msg_323.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_323.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_323.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_323.exp:1.3 Sat Oct 9 21:25:39 2021
+++ src/tests/usr.bin/xlint/lint1/msg_323.exp Sun Oct 10 09:17:24 2021
@@ -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]