Debian Codegraph @

gcc/testsuite/gcc.dg/c23-attr-fallthrough-2.c

raw
1 /* Test C23 attribute syntax. Invalid use of fallthrough attribute. */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c23 -pedantic-errors -Wextra" } */
4
5 [[fallthrough]]; /* { dg-error "'fallthrough' attribute at top level" } */
6
7 int [[fallthrough]] x; /* { dg-error "ignored" } */
8
9 int g () [[fallthrough]]; /* { dg-error "ignored" } */
10
11 int array[2] [[fallthrough]]; /* { dg-error "ignored" } */
12
13 int z = sizeof (int [[fallthrough]]); /* { dg-error "ignored" } */
14
15 int
16 f (int a)
17 {
18 [[fallthrough]] int b = 2; /* { dg-warning "not followed by" } */
19 /* { dg-error "ignored" "ignored" { target *-*-* } .-1 } */
20 switch (a)
21 {
22 case 1:
23 b = 1; /* { dg-warning "may fall through" } */
24 case 2:
25 b = 2; /* { dg-warning "may fall through" } */
26 [[fallthrough()]]; /* { dg-error "does not take any arguments" } */
27 case 3:
28 b += 7;
29 break;
30 case 4:
31 b = 4; /* { dg-warning "may fall through" } */
32 [[fallthrough(1)]]; /* { dg-error "does not take any arguments|expected" } */
33 case 5:
34 b += 5;
35 break;
36 [[fallthrough]] case 6: break; /* { dg-error "ignored" } */
37 [[fallthrough]] default: break; /* { dg-error "ignored" } */
38 }
39 [[fallthrough]] return b; /* { dg-error "ignored" } */
40 [[fallthrough]] label: ; /* { dg-error "ignored" } */
41 goto label;
42 }