xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_382.c (revision a53894b635e673440a046eb87c721c3a133147e7)
1 /*	$NetBSD: msg_382.c,v 1.1 2024/07/10 20:33:38 rillig Exp $	*/
2 # 3 "msg_382.c"
3 
4 // Test for message: constant assignment of type '%s' in operand of '!' always evaluates to '%s' [382]
5 
6 /*
7  * Outside strict bool mode, an assignment can be used as a condition, but
8  * that is generally wrong.  Especially if a constant is assigned to a
9  * variable, the condition always evaluates to that constant value, which
10  * indicates a typo, as '==' makes more sense than '=' in a condition.
11  */
12 
13 /* lint1-extra-flags: -X 351 */
14 
15 int
16 /* expect+1: warning: parameter 'b' unused in function 'conversions' [231] */
conversions(int a,int b)17 conversions(int a, int b)
18 {
19 	/* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'true' [382] */
20 	if (!(a = 13))
21 		return 1;
22 	/* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'false' [382] */
23 	if (!(b = 0))
24 		return 2;
25 	if (!(a = a + 1))
26 		return 3;
27 	return a;
28 }
29