1 /* $NetBSD: msg_382.c,v 1.2 2025年04月12日 17:22:50 rillig Exp $ */ 2# 3 "msg_382.c" 3 4 // Test for message: constant assignment of type '%s' in operand of '%s' 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 conversions(int a, int b) 17{ 18 /* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'true' [382] */ 19 if (!(a = 13)) 20 return 1; 21 /* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'false' [382] */ 22 if (!(b = 0)) 23 return 2; 24 if (!(a = a + 1)) 25 return 3; 26 27 /* expect+1: warning: constant assignment of type 'int' in operand of '&&' always evaluates to 'true' [382] */ 28 if ((a = 13) && (b == 14)) 29 return 4; 30 /* expect+1: warning: constant assignment of type 'int' in operand of '&&' always evaluates to 'true' [382] */ 31 if ((a == 13) && (b = 14)) 32 return 5; 33 34 /* expect+1: warning: constant assignment of type 'int' in operand of '||' always evaluates to 'true' [382] */ 35 if ((a = 13) || (b == 14)) 36 return 4; 37 /* expect+1: warning: constant assignment of type 'int' in operand of '||' always evaluates to 'true' [382] */ 38 if ((a == 13) || (b = 14)) 39 return 5; 40 41 return a; 42} 43