1 /* $NetBSD: msg_159.c,v 1.4 2022/07/06 21:13:13 rillig Exp $ */ 2 # 3 "msg_159.c" 3 4 // Test for message: assignment in conditional context [159] 5 6 /* lint1-extra-flags: -h */ 7 8 const char * 9 example(int a, int b) 10 { 11 12 if (a == b) 13 return "comparison, not parenthesized"; 14 15 if ((a == b)) 16 return "comparison, parenthesized"; 17 18 if ( 19 # 20 "msg_159.c" 3 4 20 (a == b) 21 # 22 "msg_159.c" 22 ) 23 return "comparison, parenthesized, from system header"; 24 25 /* expect+1: warning: assignment in conditional context [159] */ 26 if (a = b) 27 return "assignment, not parenthesized"; 28 29 /* 30 * XXX: GCC has the convention that an assignment that is 31 * parenthesized is intended as an assignment. 32 */ 33 /* expect+1: warning: assignment in conditional context [159] */ 34 if ((a = b)) 35 return "assignment, parenthesized"; 36 37 if ((a = b) != 0) 38 return "explicit comparison after assignment"; 39 40 return "other"; 41 } 42