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