xref: /netbsd-src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: gcc_attribute_stmt.c,v 1.3 2022/04/28 21:38:38 rillig Exp $	*/
2 # 3 "gcc_attribute_stmt.c"
3 
4 /*
5  * Tests for the GCC __attribute__ for statements.
6  *
7  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html
8  */
9 
10 void println(const char *);
11 
12 void
13 attribute_fallthrough(int i)
14 {
15 	switch (i) {
16 	case 5:
17 		/*
18 		 * The attribute 'fallthrough' is only valid after a
19 		 * preceding statement. This is already caught by GCC, so
20 		 * lint does not need to care.
21 		 */
22 		__attribute__((__fallthrough__));
23 	case 3:
24 		println("odd");
25 		__attribute__((__fallthrough__));
26 	case 2:
27 		/*
28 		 * Only the null statement can have the attribute
29 		 * 'fallthrough'. This is already caught by GCC, so
30 		 * lint does not need to care.
31 		 */
32 		/* expect+2: error: syntax error '__attribute__' [249] */
33 		println("prime")
34 		    __attribute__((__fallthrough__));
35 	}
36 }
37