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