1 /* $NetBSD: msg_379.c,v 1.1 2024/05/11 15:53:38 rillig Exp $ */ 2 # 3 "msg_379.c" 3 4 // Test for message: comparing integer '%s' to floating point constant %Lg [379] 5 6 /* 7 * Comparing an integer expression to a floating point constant mixes 8 * different kinds of types. This mixture is more complicated than necessary, 9 * thus confusing human readers. 10 * 11 * The compilers are fine with this kind of expression: GCC treats the 12 * constant as an integer even at -O0 while Clang needs at least -O. 13 */ 14 15 /* lint1-extra-flags: -X 351 */ 16 17 int 18 comparisons(int x) 19 { 20 if (3 > 123.0) 21 /* expect+1: warning: statement not reached [193] */ 22 return 0; 23 /* expect+1: warning: comparing integer 'int' to floating point constant 123 [379] */ 24 if (x > 123.0) 25 return 1; 26 27 // Yoda-style comparisons are unusual enough to not warn about them. 28 if (123.0 > x) 29 return 2; 30 return 3; 31 } 32