xref: /netbsd-src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: d_gcc_compound_statements1.c,v 1.11 2022/06/15 18:11:02 rillig Exp $	*/
2 # 3 "d_gcc_compound_statements1.c"
3 
4 /* GCC compound statement with expression */
5 
6 /*
7  * Compound statements are only allowed in functions, not at file scope.
8  *
9  * Before decl.c 1.283 from 2022-05-31, lint crashed with a segmentation
10  * fault due to the unused label.
11  */
12 int invalid_gcc_statement_expression = ({
13 unused_label:
14 	3;
15 /* expect+2: error: syntax error 'labels are only valid inside a function' [249] */
16 /* expect+1: error: cannot initialize 'int' from 'void' [185] */
17 });
18 
19 void foo(unsigned long z)
20 {
21 	z = ({
22 		unsigned long tmp;
23 		tmp = 1;
24 		tmp;
25 	});
26 	foo(z);
27 }
28 
29 /*
30  * Compound statements are only allowed in functions, not at file scope.
31  *
32  * Before decl.c 1.186 from 2021-06-19, lint crashed with a segmentation
33  * fault.
34  */
35 int c = ({
36 	/* expect+1: error: syntax error 'return outside function' [249] */
37 	return 3;
38 });
39 /* expect-1: error: cannot initialize 'int' from 'void' [185] */
40 
41 void
42 function(void)
43 {
44 	/*
45 	 * Before cgram.y 1.229 from 2021-06-20, lint crashed due to the
46 	 * syntax error, which made an expression NULL.
47 	 */
48 	({
49 		/* expect+1: error: type 'int' does not have member 'e' [101] */
50 		0->e;
51 	});
52 }
53 
54 void
55 crash(void)
56 {
57 	/*
58 	 * Before tree.c 1.418 from 2022-04-03, lint dereferenced a null
59 	 * pointer in do_statement_expr.
60 	 */
61 	({
62 		/* expect+1: error: syntax error ';' [249] */
63 		;
64 	});
65 }
66