Module Name: src
Committed By: rillig
Date: Sun Jul 11 18:58:13 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
src/tests/usr.bin/xlint/lint1: stmt_if.c stmt_if.exp
Log Message:
tests/lint: test dangling else
To generate a diff of this commit:
cvs rdiff -u -r1.1083 -r1.1084 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.84 -r1.85 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/stmt_if.c \
src/tests/usr.bin/xlint/lint1/stmt_if.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1083 src/distrib/sets/lists/tests/mi:1.1084
--- src/distrib/sets/lists/tests/mi:1.1083 Sat Jul 10 18:25:57 2021
+++ src/distrib/sets/lists/tests/mi Sun Jul 11 18:58:13 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1083 2021/07/10 18:25:57 rillig Exp $
+# $NetBSD: mi,v 1.1084 2021/07/11 18:58:13 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6976,6 +6976,8 @@
./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/stmt_for.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/stmt_for.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/stmt_if.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/stmt_if.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/t_integration tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/ztest tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/ztest/Atffile tests-usr.bin-tests compattestfile,atf
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.84 src/tests/usr.bin/xlint/lint1/Makefile:1.85
--- src/tests/usr.bin/xlint/lint1/Makefile:1.84 Sat Jul 10 18:25:57 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile Sun Jul 11 18:58:13 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.84 2021/07/10 18:25:57 rillig Exp $
+# $NetBSD: Makefile,v 1.85 2021/07/11 18:58:13 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 345 # see lint1/err.c
@@ -181,6 +181,8 @@ FILES+= op_shl_lp64.c
FILES+= op_shl_lp64.exp
FILES+= stmt_for.c
FILES+= stmt_for.exp
+FILES+= stmt_if.c
+FILES+= stmt_if.exp
# Note: only works for adding tests.
# To remove a test, the $$mi file must be edited manually.
Added files:
Index: src/tests/usr.bin/xlint/lint1/stmt_if.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/stmt_if.c:1.1
--- /dev/null Sun Jul 11 18:58:13 2021
+++ src/tests/usr.bin/xlint/lint1/stmt_if.c Sun Jul 11 18:58:13 2021
@@ -0,0 +1,28 @@
+/* $NetBSD: stmt_if.c,v 1.1 2021/07/11 18:58:13 rillig Exp $ */
+# 3 "stmt_if.c"
+
+/*
+ * Test parsing of 'if' statements.
+ */
+
+void println(const char *);
+
+void
+dangling_else(int x)
+{
+ if (x > 0)
+ if (x > 10)
+ println("> 10");
+ /* This 'else' is bound to the closest unfinished 'if'. */
+ else
+ println("> 0");
+ /*
+ * If the above 'else' were bound to the other 'if', the next 'else'
+ * would have no corresponding 'if', resulting in a syntax error.
+ */
+ else
+ println("not positive");
+ /* expect+1: syntax error 'else' [249] */
+ else
+ println("syntax error");
+}
Index: src/tests/usr.bin/xlint/lint1/stmt_if.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/stmt_if.exp:1.1
--- /dev/null Sun Jul 11 18:58:13 2021
+++ src/tests/usr.bin/xlint/lint1/stmt_if.exp Sun Jul 11 18:58:13 2021
@@ -0,0 +1 @@
+stmt_if.c(26): error: syntax error 'else' [249]