source:
tests/ctrl-flow/fallthrough.cfa@
5db17077
Last change on this file since 5db17077 was d96f7c4, checked in by , 8 months ago | |
---|---|
|
|
File size: 2.4 KB |
Rev | Line | |
---|---|---|
[e2c70ab] | 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 | // | |
[dc8511c] | 7 | // fallthrough.cfa -- |
[e2c70ab] | 8 | // |
9 | // Author : Rob Schluntz | |
10 | // Created On : Wed Mar 14 10:06:25 2018 | |
[13f5a70] | 11 | // Last Modified By : Peter A. Buhr |
[d96f7c4] | 12 | // Last Modified On : Fri Jan 17 14:09:49 2025 |
13 | // Update Count : 23 | |
[e2c70ab] | 14 | // |
15 | ||
[303d866] | 16 | #include <fstream.hfa> |
17 | ||
[e2c70ab] | 18 | void test(int choice) { |
19 | choose ( choice ) { | |
[5ea5b28] | 20 | case 1: |
21 | sout | "case 1"; | |
[d96f7c4] | 22 | fallthrough; |
[5ea5b28] | 23 | case 2: |
24 | sout | "case 2"; | |
[d96f7c4] | 25 | fallthrough; |
26 | sout | "did not fallthrough"; | |
27 | if ( 7 ) fallthrough common2; | |
28 | fallthrough common1; | |
[5ea5b28] | 29 | case 3: |
30 | sout | "case 3"; | |
[d96f7c4] | 31 | fallthrough default; |
32 | fallthrough common1; | |
[5ea5b28] | 33 | common1: |
34 | sout | "common1"; | |
[13f5a70] | 35 | // break |
[5ea5b28] | 36 | case 4: |
37 | sout | "case 4"; | |
[d96f7c4] | 38 | fallthrough common2; |
[5ea5b28] | 39 | case 5: |
40 | sout | "case 5"; | |
[d96f7c4] | 41 | fallthrough common2; |
42 | fallthrough default; | |
[5ea5b28] | 43 | case 6: |
44 | sout | "case 6"; | |
[d96f7c4] | 45 | fallthrough common2; |
[5ea5b28] | 46 | common2: |
47 | sout | "common2"; | |
[13f5a70] | 48 | // break |
[5ea5b28] | 49 | default: |
50 | sout | "default"; | |
[d96f7c4] | 51 | fallthrough; |
[5ea5b28] | 52 | } // choose |
[e2c70ab] | 53 | |
[200fcb3] | 54 | sout | nl; |
[13f5a70] | 55 | |
56 | switch ( choice ) { | |
57 | case 1: | |
[200fcb3] | 58 | sout | "case 1"; |
[13f5a70] | 59 | switch ( choice ) { |
60 | case 1: | |
[200fcb3] | 61 | sout | "case 1"; |
[13f5a70] | 62 | for ( int i = 0; i < 4; i += 1 ) { |
[f498c51] | 63 | sout | i; |
[d96f7c4] | 64 | if ( i == 2 ) fallthrough common; |
[13f5a70] | 65 | } // for |
66 | } // switch | |
67 | break; | |
68 | case 5: | |
[200fcb3] | 69 | sout | "case 5"; |
[13f5a70] | 70 | if ( choice == 5 ) { |
71 | if ( choice != 5 ) { | |
[200fcb3] | 72 | sout | "error"; |
[13f5a70] | 73 | } else { |
[200fcb3] | 74 | sout | "check"; |
[d96f7c4] | 75 | fallthrough common; |
[13f5a70] | 76 | } // if |
77 | } // if | |
78 | common: | |
[f498c51] | 79 | sout | "common"; |
[d96f7c4] | 80 | fallthrough; |
[13f5a70] | 81 | break; |
82 | default: | |
[f498c51] | 83 | sout | "default"; |
[d96f7c4] | 84 | fallthrough; |
[13f5a70] | 85 | } // switch |
86 | ||
[e2c70ab] | 87 | #if ERR1 |
88 | // ERROR: fallthrough must be enclosed in switch or choose | |
[d96f7c4] | 89 | fallthrough; |
[e2c70ab] | 90 | // ERROR: fallthrough must be enclosed in switch or choose |
[d96f7c4] | 91 | fallthrough common4; |
[e2c70ab] | 92 | // ERROR: fallthrough must be enclosed in switch or choose |
[d96f7c4] | 93 | fallthrough default; |
[e2c70ab] | 94 | choose ( 3 ) { |
[5ea5b28] | 95 | case 2: |
96 | for () { | |
97 | choose ( 2 ) { | |
98 | case 1: | |
99 | // ERROR: default is later, but in a different switch | |
[d96f7c4] | 100 | fallthrough default; |
[5ea5b28] | 101 | // ERROR: common3 is later, but not at the same level as a case clause |
[d96f7c4] | 102 | fallthrough common3; |
[e2c70ab] | 103 | } |
[5ea5b28] | 104 | common3: ; |
105 | } // for | |
106 | default: | |
107 | case 1: | |
108 | common4: | |
109 | // ERROR: attempt to jump up with fallthrough | |
[d96f7c4] | 110 | if ( 7 ) fallthrough common4; |
[5ea5b28] | 111 | // ERROR: attempt to jump up with fallthrough |
[d96f7c4] | 112 | fallthrough default; |
[5ea5b28] | 113 | } // choose |
[e2c70ab] | 114 | #endif |
115 | } | |
116 | ||
117 | int main() { | |
[303d866] | 118 | test( 1 ); |
[200fcb3] | 119 | sout | nl; |
[303d866] | 120 | test( 5 ); |
[e2c70ab] | 121 | } |
122 | ||
123 | // Local Variables: // | |
124 | // tab-width: 4 // | |
[dc8511c] | 125 | // compile-command: "cfa fallthrough.cfa" // |
[e2c70ab] | 126 | // End: // |
Note:
See TracBrowser
for help on using the repository browser.