xref: /netbsd-src/tests/usr.bin/xlint/lint1/stmt_if.c (revision b2baa50111d645353fa30b4deab0f79d93650c8c)
1 /*	$NetBSD: stmt_if.c,v 1.3 2023/03/28 14:44:35 rillig Exp $	*/
2 # 3 "stmt_if.c"
3 
4 /*
5  * Test parsing of 'if' statements.
6  */
7 
8 /* lint1-extra-flags: -X 351 */
9 
10 void println(const char *);
11 
12 void
dangling_else(int x)13 dangling_else(int x)
14 {
15 	if (x > 0)
16 		if (x > 10)
17 			println("> 10");
18 		/* This 'else' is bound to the closest unfinished 'if'. */
19 		else
20 			println("> 0");
21 	/*
22 	 * If the above 'else' were bound to the other 'if', the next 'else'
23 	 * would have no corresponding 'if', resulting in a syntax error.
24 	 */
25 	else
26 		println("not positive");
27 	/* expect+1: error: syntax error 'else' [249] */
28 	else
29 		println("syntax error");
30 }
31