[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / c2x-fallthrough.c
blobbaa62aa8f140114ad1879063375ea5e651fb0096
1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
3 void f(int n) {
4 switch (n) {
5 case 0:
6 n += 1;
7 [[fallthrough]]; // ok
8 case 1:
9 if (n) {
10 [[fallthrough]]; // ok
11 } else {
12 return;
14 case 2:
15 for (int n = 0; n != 10; ++n)
16 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
17 case 3:
18 while (1)
19 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
20 case 4:
21 while (0)
22 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
23 case 5:
24 do [[fallthrough]]; while (1); // expected-error {{does not directly precede switch label}}
25 case 6:
26 do [[fallthrough]]; while (0); // expected-error {{does not directly precede switch label}}
27 case 7:
28 switch (n) {
29 case 0:
30 // FIXME: This should be an error, even though the next thing we do is to
31 // fall through in an outer switch statement.
32 [[fallthrough]];
34 case 8:
35 [[fallthrough]]; // expected-error {{does not directly precede switch label}}
36 goto label;
37 label:
38 case 9:
39 n += 1;
40 case 10: // no warning, -Wimplicit-fallthrough is not enabled in this test, and does not need to
41 // be enabled for these diagnostics to be produced.
42 break;
46 [[fallthrough]] typedef int n1; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
47 typedef int [[fallthrough]] n2; // expected-error {{'fallthrough' attribute cannot be applied to types}}
48 typedef int n3 [[fallthrough]]; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
50 enum [[fallthrough]] E { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
51 One
53 struct [[fallthrough]] S { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
54 int i;
57 [[fallthrough]] // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
58 void g(void) {
59 [[fallthrough]] int n; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
60 [[fallthrough]] ++n; // expected-error {{'fallthrough' attribute only applies to empty statements}}
62 switch (n) {
63 // FIXME: This should be an error.
64 [[fallthrough]];
65 return;
67 case 0:
68 [[fallthrough, fallthrough]]; // ok
69 case 1:
70 [[fallthrough(0)]]; // expected-error {{argument list}}
71 case 2:
72 break;