blob: 2fd69c4da0f2551f145e55f2cfd87e9b856d936a [file] [log] [blame]
Aaron Ballman8c6b1a32017-10-18 14:33:27 +00001// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
2
3void 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;
13 }
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]];
33 }
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;
43 }
44}
45
Aaron Ballman8eab4e52017-10-18 14:48:33 +000046[[fallthrough]] typedef int n1; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
47typedef int [[fallthrough]] n2; // expected-error {{'fallthrough' attribute cannot be applied to types}}
48typedef int n3 [[fallthrough]]; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
Aaron Ballman8c6b1a32017-10-18 14:33:27 +000049
50enum [[fallthrough]] E { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
51 One
52};
53struct [[fallthrough]] S { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
54 int i;
55};
56
57[[fallthrough]] // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
58void g(void) {
59 [[fallthrough]] int n; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}
60 [[fallthrough]] ++n; // expected-error-re {{{{^}}fallthrough attribute is only allowed on empty statements}}
61
62 switch (n) {
63 // FIXME: This should be an error.
64 [[fallthrough]];
65 return;
66
67 case 0:
68 [[fallthrough, fallthrough]]; // expected-error {{multiple times}}
69 case 1:
70 [[fallthrough(0)]]; // expected-error {{argument list}}
71 case 2:
72 break;
73 }
74}
75