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