Module Name:    src
Committed By:   rillig
Date:           Fri Apr 19 20:59:18 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_207.c

Log Message:
tests/lint: show how to trigger message 207


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_207.c

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_207.c
diff -u src/tests/usr.bin/xlint/lint1/msg_207.c:1.3 src/tests/usr.bin/xlint/lint1/msg_207.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_207.c:1.3	Thu Jun 16 21:24:41 2022
+++ src/tests/usr.bin/xlint/lint1/msg_207.c	Fri Apr 19 20:59:18 2024
@@ -1,8 +1,51 @@
-/*	$NetBSD: msg_207.c,v 1.3 2022/06/16 21:24:41 rillig Exp $	*/
+/*	$NetBSD: msg_207.c,v 1.4 2024/04/19 20:59:18 rillig Exp $	*/
 # 3 "msg_207.c"
 
 // Test for message: loop not entered at top [207]
 
-/* expect+1: error: syntax error ':' [249] */
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+static void
+/* expect+1: warning: static function 'for_loop' unused [236] */
+for_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			for (i = 0;
+			    i < 5;
+				/* expect+2: warning: loop not entered at top [207] */
+				/* expect+1: warning: end-of-loop code not reached [223] */
+			    i += 4)
+				return;
+
+	// XXX: Why is this different from the snippet above?
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: statement not reached [193] */
+			for (int j = 0;
+			    j < 5;
+			    /* expect+1: warning: end-of-loop code not reached [223] */
+			    j += 4)
+				return;
+}
+
+static void
+/* expect+1: warning: static function 'while_loop' unused [236] */
+while_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: loop not entered at top [207] */
+			while (i < 5)
+				i += 4;
+}
+
+static void
+/* expect+1: warning: static function 'do_loop' unused [236] */
+do_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: loop not entered at top [207] */
+			do {
+				i += 4;
+			} while (i < 5);
+}

Reply via email to