Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / c2x-fallthrough.c
blob092d5285f80bac5c2a497713ce14effb57e4896f
1 // RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
3 // This is the latest version of fallthrough that we support.
4 _Static_assert(__has_c_attribute(fallthrough) == 201910L);
6 void f(int n) {
7 switch (n) {
8 case 0:
9 n += 1;
10 [[fallthrough]]; // ok
11 case 1:
12 if (n) {
13 [[fallthrough]]; // ok
14 } else {
15 return;
17 case 2:
18 for (int n = 0; n != 10; ++n)
19 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
20 case 3:
21 while (1)
22 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
23 case 4:
24 while (0)
25 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
26 case 5:
27 do [[fallthrough]]; while (1); // expected-error {{does not directly precede switch label}}
28 case 6:
29 do [[fallthrough]]; while (0); // expected-error {{does not directly precede switch label}}
30 case 7:
31 switch (n) {
32 case 0:
33 // FIXME: This should be an error, even though the next thing we do is to
34 // fall through in an outer switch statement.
35 [[fallthrough]];
37 case 8:
38 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
39 goto label;
40 label:
41 case 9:
42 n += 1;
43 case 10: // no warning, -Wimplicit-fallthrough is not enabled in this test, and does not need to
44 // be enabled for these diagnostics to be produced.
45 break;
49 [[fallthrough]] typedef int n1; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
50 typedef int [[fallthrough]] n2; // expected-error {{'fallthrough' attribute cannot be applied to types}}
51 typedef int n3 [[fallthrough]]; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
53 enum [[fallthrough]] E { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
54 One
56 struct [[fallthrough]] S { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
57 int i;
60 [[fallthrough]] // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
61 void g(void) {
62 [[fallthrough]] int n; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
63 [[fallthrough]] ++n; // expected-error {{'fallthrough' attribute only applies to empty statements}}
65 switch (n) {
66 // FIXME: This should be an error.
67 [[fallthrough]];
68 return;
70 case 0:
71 [[fallthrough, fallthrough]]; // ok
72 case 1:
73 [[fallthrough(0)]]; // expected-error {{argument list}}
74 case 2:
75 break;