xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_385.c (revision a8016b51bcf5204ff836e46c2432dc27e5b12586)
1 /*	$NetBSD: msg_385.c,v 1.1 2024/12/08 17:12:01 rillig Exp $	*/
2 # 3 "msg_385.c"
3 
4 // Test for message: do-while macro '%.*s' ends with semicolon [385]
5 
6 /*
7  * A function-like macro that consists of a do-while statement is intended to
8  * expand to a single statement, but without the trailing semicolon, as the
9  * semicolon is already provided by the calling site. When the macro expansion
10  * ends with a semicolon, there are two semicolons, which can lead to syntax
11  * errors.
12  */
13 
14 /* lint1-extra-flags: -X 351 */
15 
16 /* expect+1: warning: do-while macro 'wrong_stmt' ends with semicolon [385] */
17 #define		wrong_stmt()	do { } while (0);
18 
19 #define		correct_stmt()	do { } while (0)
20 
21 /* expect+5: warning: do-while macro 'wrong_stmt_with_comment' ends with semicolon [385] */
22 #define wrong_stmt_with_comment() do { } while (0); /*
23 a
24 b
25 c
26 */
27 
28 #define correct_stmt_with_comment() do { } while (0) /*
29 a
30 b
31 c
32 */
33 
34 /* The comment marker inside the string literal does not start a comment. */
35 #define stmt_with_string() do { print("/*"); } while (0)
36 
37 void
38 call_wrong_stmt(int x)
39 {
40 	if (x > 0)
41 		do { } while (0);;
42 	/* expect+1: error: syntax error 'else' [249] */
43 	else
44 		do { } while (0);;
45 }
46 
47 void
48 call_correct_stmt(int x)
49 {
50 	if (x < 0)
51 		do { } while (0);
52 	else
53 		do { } while (0);
54 }
55