Home | History | Annotate | Line # | Download | only in lint1
msg_220.c revision 1.4
      1 /*	$NetBSD: msg_220.c,v 1.4 2021/08/29 08:57:50 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 		/* FALL THROUGH */
     56 		/* expect+1: warning: fallthrough on case statement [220] */
     57 	case 2:
     58 		println("2");
     59 		/* FALLS THROUGH */
     60 		/* expect+1: warning: fallthrough on case statement [220] */
     61 	case 3:
     62 		println("3");
     63 		/* intentionally falls through */
     64 		/* expect+1: warning: fallthrough on case statement [220] */
     65 	case 4:
     66 		println("4");
     67 		/* @fallthrough@ */
     68 		/* expect+1: warning: fallthrough on case statement [220] */
     69 	case 5:
     70 		println("5");
     71 	}
     72 }
     73