1 1.4 rillig /* $NetBSD: msg_217.c,v 1.4 2021/02/21 09:17:55 rillig Exp $ */ 2 1.1 rillig # 3 "msg_217.c" 3 1.1 rillig 4 1.1 rillig // Test for message: function %s falls off bottom without returning value [217] 5 1.1 rillig 6 1.2 rillig int 7 1.2 rillig random(int n) 8 1.2 rillig { 9 1.2 rillig if (n < 0) 10 1.2 rillig return -3; 11 1.2 rillig } /* expect: 217 */ 12 1.3 rillig 13 1.3 rillig /* 14 1.3 rillig * The pattern 'do { } while (0)' is often used in statement macros. 15 1.3 rillig * Putting a 'return' at the end of such a macro is legitimate, the embracing 16 1.3 rillig * 'do { } while (0)' is probably there to conform to a coding standard or 17 1.3 rillig * to otherwise reduce confusion. 18 1.3 rillig * 19 1.3 rillig * Seen in external/bsd/libevent/dist/event_tagging.c, function 20 1.3 rillig * encode_int_internal. 21 1.3 rillig * 22 1.3 rillig * As of 2021-01-31, lint wrongly reports that the function would fall off 23 1.3 rillig * the bottom, but it cannot reach the bottom since every path contains the 24 1.3 rillig * 'return i'. 25 1.3 rillig */ 26 1.3 rillig int 27 1.3 rillig do_while_return(int i) 28 1.3 rillig { 29 1.3 rillig do { 30 1.3 rillig return i; 31 1.3 rillig } while (/*CONSTCOND*/0); /*FIXME*//* expect: 193 */ 32 1.3 rillig } /*FIXME*//* expect: 217 */ 33 1.4 rillig 34 1.4 rillig /* 35 1.4 rillig * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception, 36 1.4 rillig * the function 'main' does not have to return a value, reaching the bottom 37 1.4 rillig * is equivalent to returning 0. 38 1.4 rillig * 39 1.4 rillig * Before func.c 1.72 from 2021-02-21, lint had wrongly warned about this. 40 1.4 rillig */ 41 1.4 rillig int 42 1.4 rillig main(void) 43 1.4 rillig { 44 1.4 rillig } 45