ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change
on this file since 13f5a70 was
13f5a70,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
add another test
|
-
Property mode set to
100644
|
File size:
2.4 KB
|
Line | |
---|
1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // fallthrough.c -- |
---|
8 | // |
---|
9 | // Author : Rob Schluntz |
---|
10 | // Created On : Wed Mar 14 10:06:25 2018 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Wed Mar 14 22:45:13 2018 |
---|
13 | // Update Count : 13 |
---|
14 | // |
---|
15 | |
---|
16 | void test(int choice) { |
---|
17 | choose ( choice ) { |
---|
18 | case 1: |
---|
19 | printf("case 1\n"); |
---|
20 | fallthru; |
---|
21 | case 2: |
---|
22 | printf("case 2\n"); |
---|
23 | fallthru; |
---|
24 | printf("did not fallthru\n"); |
---|
25 | if ( 7 ) fallthru common2; |
---|
26 | fallthru common1; |
---|
27 | case 3: |
---|
28 | printf("case 3\n"); |
---|
29 | fallthru default; |
---|
30 | fallthru common1; |
---|
31 | common1: |
---|
32 | printf("common1\n"); |
---|
33 | // break |
---|
34 | case 4: |
---|
35 | printf("case 4\n"); |
---|
36 | fallthru common2; |
---|
37 | case 5: |
---|
38 | printf("case 5\n"); |
---|
39 | fallthru common2; |
---|
40 | fallthru default; |
---|
41 | case 6: |
---|
42 | printf("case 6\n"); |
---|
43 | fallthru common2; |
---|
44 | common2: |
---|
45 | printf("common2\n"); |
---|
46 | // break |
---|
47 | default: |
---|
48 | printf("default\n"); |
---|
49 | fallthru; |
---|
50 | } |
---|
51 | |
---|
52 | printf("\n"); |
---|
53 | |
---|
54 | switch ( choice ) { |
---|
55 | case 1: |
---|
56 | printf("case 1\n"); |
---|
57 | switch ( choice ) { |
---|
58 | case 1: |
---|
59 | printf("case 1\n"); |
---|
60 | for ( int i = 0; i < 4; i += 1 ) { |
---|
61 | printf("%d\n", i); |
---|
62 | if ( i == 2 ) fallthru common; |
---|
63 | } // for |
---|
64 | } // switch |
---|
65 | break; |
---|
66 | case 5: |
---|
67 | printf("case 5\n"); |
---|
68 | if ( choice == 5 ) { |
---|
69 | if ( choice != 5 ) { |
---|
70 | printf("error\n"); |
---|
71 | } else { |
---|
72 | printf("check\n"); |
---|
73 | fallthru common; |
---|
74 | } // if |
---|
75 | } // if |
---|
76 | common: |
---|
77 | printf( "common\n" ); |
---|
78 | fallthru; |
---|
79 | break; |
---|
80 | default: |
---|
81 | printf( "default\n" ); |
---|
82 | fallthru; |
---|
83 | } // switch |
---|
84 | |
---|
85 | #if ERR1 |
---|
86 | // ERROR: fallthrough must be enclosed in switch or choose |
---|
87 | fallthru; |
---|
88 | // ERROR: fallthrough must be enclosed in switch or choose |
---|
89 | fallthru common4; |
---|
90 | // ERROR: fallthrough must be enclosed in switch or choose |
---|
91 | fallthru default; |
---|
92 | choose ( 3 ) { |
---|
93 | case 2: |
---|
94 | for ( ;; ) { |
---|
95 | choose ( 2 ) { |
---|
96 | case 1: |
---|
97 | // ERROR: default is later, but in a different switch |
---|
98 | fallthru default; |
---|
99 | // ERROR: common3 is later, but not at the same level as a case clause |
---|
100 | fallthru common3; |
---|
101 | } |
---|
102 | common3: ; |
---|
103 | } |
---|
104 | default: |
---|
105 | case 1: |
---|
106 | common4: |
---|
107 | // ERROR: attempt to jump up with fallthrough |
---|
108 | if ( 7 ) fallthru common4; |
---|
109 | // ERROR: attempt to jump up with fallthrough |
---|
110 | fallthru default; |
---|
111 | } |
---|
112 | #endif |
---|
113 | } |
---|
114 | |
---|
115 | int main() { |
---|
116 | test(1); |
---|
117 | printf("\n"); |
---|
118 | test(5); |
---|
119 | } |
---|
120 | |
---|
121 | // Local Variables: // |
---|
122 | // tab-width: 4 // |
---|
123 | // compile-command: "cfa fallthrough.c" // |
---|
124 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.