Home | History | Annotate | Line # | Download | only in lint1
msg_217.c revision 1.10
      1 /*	$NetBSD: msg_217.c,v 1.10 2022/06/16 21:24:41 rillig Exp $	*/
      2 # 3 "msg_217.c"
      3 
      4 // Test for message: function %s falls off bottom without returning value [217]
      5 
      6 int
      7 random(int n)
      8 {
      9 	if (n < 0)
     10 		return -3;
     11 }
     12 /* expect-1: warning: function random falls off bottom without returning value [217] */
     13 
     14 /*
     15  * The pattern 'do { } while (0)' is often used in statement macros.
     16  * Putting a 'return' at the end of such a macro is legitimate, the embracing
     17  * 'do { } while (0)' is probably there to conform to a coding standard or
     18  * to otherwise reduce confusion.
     19  *
     20  * Seen in external/bsd/libevent/dist/event_tagging.c, function
     21  * encode_int_internal.
     22  *
     23  * Before tree.c 1.243 from 2021-03-21, lint wrongly reported that the
     24  * 'while 0' was unreachable.  This has been fixed by allowing the 'while 0'
     25  * in a do-while-false loop to be unreachable.  The same could be useful for a
     26  * do-while-true.
     27  *
     28  * Before func.c 1.83 from 2021-03-21, lint wrongly reported that the function
     29  * would fall off the bottom.
     30  */
     31 int
     32 do_while_return(int i)
     33 {
     34 	do {
     35 		return i;
     36 	} while (0);
     37 }
     38 
     39 /*
     40  * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,
     41  * the function 'main' does not have to return a value, reaching the bottom
     42  * is equivalent to returning 0.
     43  *
     44  * Before func.c 1.72 from 2021-02-21, lint had wrongly warned about this.
     45  */
     46 int
     47 main(void)
     48 {
     49 }
     50 
     51 int
     52 reachable_continue_leads_to_endless_loop(void)
     53 {
     54 	for (;;) {
     55 		if (1)
     56 			continue;
     57 		break;
     58 	}
     59 }
     60 
     61 int
     62 unreachable_continue_falls_through(void)
     63 {
     64 	for (;;) {
     65 		if (0)
     66 			/* expect+1: warning: statement not reached [193] */
     67 			continue;
     68 		break;
     69 	}
     70 }
     71 /* expect-1: warning: function unreachable_continue_falls_through falls off bottom without returning value [217] */
     72