Home | History | Annotate | Line # | Download | only in lint1
msg_220.c revision 1.7
      1 /*	$NetBSD: msg_220.c,v 1.7 2021/08/29 09:29:32 rillig Exp $	*/
      2 # 3 "msg_220.c"
      3 
      4 // Test for message: fallthrough on case statement [220]
      5 
      6 /* lint1-extra-flags: -h */
      7 
      8 extern void
      9 println(const char *);
     10 
     11 void
     12 example(int n)
     13 {
     14 	switch (n) {
     15 	case 1:
     16 	case 3:
     17 	case 5:
     18 		println("odd");
     19 	case 2:			/* expect: 220 */
     20 	case 7:
     21 		println("prime");
     22 	default:		/* expect: 284 */
     23 		println("number");
     24 	}
     25 }
     26 
     27 void
     28 example1(int n)
     29 {
     30 	switch (n) {
     31 	case 1:
     32 	case 3:
     33 	case 5:
     34 		println("odd");
     35 		__attribute__((__fallthrough__));
     36 	case 2:
     37 	case 7:
     38 		println("prime");
     39 		__attribute__((__fallthrough__));
     40 	default:
     41 		println("number");
     42 	}
     43 }
     44 
     45 /* https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough */
     46 void
     47 annotation_comment_variations(int n)
     48 {
     49 	switch (n) {
     50 	case 0:
     51 		println("0");
     52 		/* FALLTHROUGH */
     53 	case 1:
     54 		println("1");
     55 		/* Seen in libarchive/archive_string.c, macro WRITE_UC. */
     56 		/* FALL THROUGH */
     57 		/* Lint warned before lex.c 1.79 from 2021-08-29. */
     58 	case 2:
     59 		println("2");
     60 		/* FALLS THROUGH */
     61 		/* expect+1: warning: fallthrough on case statement [220] */
     62 	case 3:
     63 		println("3");
     64 		/* intentionally falls through */
     65 		/* expect+1: warning: fallthrough on case statement [220] */
     66 	case 4:
     67 		println("4");
     68 		/* This is the Splint variant, which is seldom used. */
     69 		/* @fallthrough@ */
     70 		/* expect+1: warning: fallthrough on case statement [220] */
     71 	case 5:
     72 		println("5");
     73 		/* Seen in unbound/lookup3.c, function hashlittle. */
     74 		/* Lint warned before lex.c 1.80 from 2021-08-29. */
     75 		/* fallthrough */
     76 	case 6:
     77 		println("6");
     78 	}
     79 }
     80