1 /* $NetBSD: msg_158.c,v 1.5 2022/06/22 19:23:18 rillig Exp $ */ 2 # 3 "msg_158.c" 3 4 // Test for message: '%s' may be used before set [158] 5 6 void sink_int(int); 7 8 void 9 example(int arg) 10 { 11 int twice_arg; 12 13 /* expect+1: warning: 'twice_arg' may be used before set [158] */ 14 sink_int(twice_arg); 15 twice_arg = 2 * arg; 16 sink_int(twice_arg); 17 } 18 19 void 20 conditionally_used(int arg) 21 { 22 int twice_arg; 23 24 if (arg > 0) 25 twice_arg = 2 * arg; 26 if (arg > 0) 27 sink_int(twice_arg); 28 } 29 30 void 31 conditionally_unused(int arg) 32 { 33 int twice_arg; 34 35 if (arg > 0) 36 twice_arg = 2 * arg; 37 38 /* 39 * This situation is not detected by lint as it does not track the 40 * possible code paths for all conditions. 41 */ 42 if (arg < 0) 43 sink_int(twice_arg); 44 } 45