1 /* $NetBSD: msg_220.c,v 1.9 2023/03/28 14:44:35 rillig Exp $ */ 2 # 3 "msg_220.c" 3 4 // Test for message: fallthrough on case statement [220] 5 6 /* lint1-extra-flags: -h -X 351 */ 7 8 extern void 9 println(const char *); 10 11 void example(int n)12example(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 example1(int n)30example1(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 annotation_comment_variations(int n)49annotation_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