[553f032f] | 1 | // Check all the local control flow structures that are "sealed" by some the |
---|
| 2 | // try statement clauses; where structured programming is stricter. |
---|
[d62806c] | 3 | |
---|
| 4 | void break_in_finally() { |
---|
| 5 | while (true) { |
---|
| 6 | try {} finally { |
---|
| 7 | break; |
---|
| 8 | } |
---|
| 9 | } |
---|
| 10 | } |
---|
| 11 | |
---|
[96f5b30] | 12 | void for_break_in_finally() { |
---|
| 13 | for (10) { |
---|
| 14 | try {} finally { |
---|
| 15 | break; |
---|
| 16 | } |
---|
| 17 | } |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | void do_while_break_in_finally() { |
---|
| 21 | do { |
---|
| 22 | try {} finally { |
---|
| 23 | break; |
---|
| 24 | } |
---|
| 25 | } while (false); |
---|
| 26 | } |
---|
| 27 | |
---|
[d62806c] | 28 | void continue_in_finally() { |
---|
| 29 | while (true) { |
---|
| 30 | try {} finally { |
---|
| 31 | continue; |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void goto_in_finally() { |
---|
| 37 | while (true) { |
---|
| 38 | try {} finally { |
---|
| 39 | goto end_of_function; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | end_of_function: {} |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void labelled_break_in_finally() { |
---|
| 46 | mainLoop: while (true) { |
---|
| 47 | try {} finally { |
---|
| 48 | break mainLoop; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void labelled_continue_in_finally() { |
---|
| 54 | mainLoop: while (true) { |
---|
| 55 | try {} finally { |
---|
| 56 | continue mainLoop; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
[96f5b30] | 61 | void switch_break_in_finally() { |
---|
| 62 | switch (1) { |
---|
| 63 | case 1: |
---|
| 64 | try {} finally { |
---|
| 65 | break; |
---|
| 66 | } |
---|
| 67 | default: |
---|
| 68 | break; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void choose_break_in_finally() { |
---|
| 73 | choose (1) { |
---|
| 74 | case 1: |
---|
| 75 | try {} finally { |
---|
| 76 | break; |
---|
| 77 | } |
---|
| 78 | default: |
---|
| 79 | break; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void choose_fallthru_in_finally() { |
---|
| 84 | choose (1) { |
---|
| 85 | case 1: |
---|
| 86 | try {} finally { |
---|
| 87 | fallthru; |
---|
| 88 | } |
---|
| 89 | default: |
---|
| 90 | break; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void labelled_choose_break_in_finally() { |
---|
| 95 | mainBlock: choose (1) { |
---|
| 96 | case 1: |
---|
| 97 | try {} finally { |
---|
| 98 | break mainBlock; |
---|
| 99 | } |
---|
| 100 | case 2: |
---|
| 101 | break; |
---|
| 102 | default: |
---|
| 103 | break; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void labelled_choose_fallthru_in_finally() { |
---|
| 108 | mainBlock: choose (1) { |
---|
| 109 | case 1: |
---|
| 110 | try {} finally { |
---|
| 111 | fallthru mainBlock; |
---|
| 112 | } |
---|
| 113 | case 2: |
---|
| 114 | break; |
---|
| 115 | default: |
---|
| 116 | break; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void choose_fallthru_default_in_finally() { |
---|
| 121 | choose (1) { |
---|
| 122 | case 1: |
---|
| 123 | try {} finally { |
---|
| 124 | fallthru default; |
---|
| 125 | } |
---|
| 126 | default: |
---|
| 127 | break; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
[d62806c] | 131 | void void_return_in_finally() { |
---|
| 132 | try {} finally { |
---|
| 133 | return; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | int value_return_in_finally() { |
---|
| 138 | try {} finally { |
---|
| 139 | return -7; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | } |
---|
| 143 | |
---|
[9d6317f] | 144 | // Checked in the same place, make sure it does't break. |
---|
| 145 | void break_in_function() { |
---|
| 146 | while (true) { |
---|
| 147 | void inner() { |
---|
| 148 | break; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
[553f032f] | 153 | // Now just use return to test the other try control flow interactions. |
---|
| 154 | |
---|
| 155 | exception nil_exception {}; |
---|
| 156 | |
---|
| 157 | void return_in_try_with_catch() { |
---|
| 158 | try { |
---|
| 159 | return; |
---|
| 160 | } catch (nil_exception *) { |
---|
| 161 | ; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | // Allowed. |
---|
| 166 | void return_in_try_with_catchReturn() { |
---|
| 167 | try { |
---|
| 168 | return; |
---|
| 169 | } catchResume (nil_exception *) { |
---|
| 170 | ; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | // Allowed. |
---|
| 175 | void return_in_try_with_finally() { |
---|
| 176 | try { |
---|
| 177 | return; |
---|
| 178 | } finally { |
---|
| 179 | ; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | void return_in_catchResume() { |
---|
| 184 | try { |
---|
| 185 | ; |
---|
| 186 | } catchResume (nil_exception *) { |
---|
| 187 | return; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[d62806c] | 191 | void main() { |
---|
| 192 | // Should not compile. |
---|
| 193 | return 1; |
---|
| 194 | } |
---|