xref: /netbsd-src/tests/usr.bin/xlint/lint1/c99_bool_strict_suppressed.c (revision e6298b924c5ba98f3a22919b56dab04a87cdbb1c)
1*e6298b92Srillig /*	$NetBSD: c99_bool_strict_suppressed.c,v 1.6 2023/07/07 19:45:22 rillig Exp $	*/
230201015Srillig # 3 "c99_bool_strict_suppressed.c"
330201015Srillig 
430201015Srillig /*
530201015Srillig  * In strict bool mode, like everywhere else, individual errors can be
630201015Srillig  * suppressed.  Suppressing a message affects lint's output as well as the
730201015Srillig  * exit status.  Lint's control flow stays the same as before though.
830201015Srillig  *
930201015Srillig  * This can result in assertion failures later.  One such assertion has been
1030201015Srillig  * there since at least 1995, at the beginning of expr(), ensuring that the
1130201015Srillig  * expression is either non-null or an error message has been _printed_.
12dd4ca8c6Srillig  * In 1995, it was not possible to suppress error messages, which means that
1330201015Srillig  * the number of printed errors equaled the number of occurred errors.
1430201015Srillig  *
1530201015Srillig  * In err.c 1.12 from 2000-07-06, the option -X was added, allowing to
1630201015Srillig  * suppress individual error messages.  That commit did not mention any
17dd4ca8c6Srillig  * interaction with the assertion in expr().  The assertion was removed in
18dd4ca8c6Srillig  * tree.c 1.305 from 2021-07-04.
1930201015Srillig  */
2030201015Srillig 
21*e6298b92Srillig /* lint1-extra-flags: -T -X 107,330,331,332,333 -X 351 */
2230201015Srillig 
2330201015Srillig /* ARGSUSED */
2430201015Srillig void
test(_Bool b,int i,const char * p)2530201015Srillig test(_Bool b, int i, const char *p)
2630201015Srillig {
2730201015Srillig 
2838789a3fSrillig 	/* suppressed+1: error: controlling expression must be bool, not 'int' [333] */
2930201015Srillig 	while (1)
3030201015Srillig 		break;
3130201015Srillig 
32a8941949Srillig 	/* suppressed+1: error: operands of '=' have incompatible types '_Bool' and 'int' [107] */
3330201015Srillig 	b = i;
3430201015Srillig 
3538789a3fSrillig 	/* suppressed+1: error: operand of '!' must be bool, not 'int' [330] */
3630201015Srillig 	b = !i;
3730201015Srillig 
3838789a3fSrillig 	/* suppressed+1: error: left operand of '&&' must be bool, not 'int' [331] */
3930201015Srillig 	b = i && b;
4030201015Srillig 
4138789a3fSrillig 	/* suppressed+1: error: right operand of '&&' must be bool, not 'int' [332] */
4230201015Srillig 	b = b && i;
4330201015Srillig }
44