Last change
on this file since 433e2c3 was
c248b39,
checked in by Andrew Beach <ajbeach@…>, 4 months ago
|
Unlabelled breaks were not targetting the correct enclosing control structures. Also added a test and improved error messages.
|
-
Property mode set to
100644
|
File size:
607 bytes
|
Line | |
---|
1 | // Test breaking to unusual (non-loop, non-switch) statements. |
---|
2 | |
---|
3 | #include <fstream.hfa> |
---|
4 | |
---|
5 | void breakTargetLabels() { |
---|
6 | sout | "if"; |
---|
7 | Lif: if ( true ) { |
---|
8 | break Lif; |
---|
9 | sout | "!"; |
---|
10 | } |
---|
11 | sout | "end" | nl; |
---|
12 | |
---|
13 | sout | "block"; |
---|
14 | Lblock: { |
---|
15 | break Lblock; |
---|
16 | sout | "!"; |
---|
17 | } |
---|
18 | sout | "end" | nl; |
---|
19 | } |
---|
20 | |
---|
21 | void breakSkipsUnlabelled() { |
---|
22 | sout | "unlabelled"; |
---|
23 | for (int i = 0 ; i < 2 ; ++i) { |
---|
24 | sout | "loop"; |
---|
25 | block: { |
---|
26 | break; |
---|
27 | sout | "!"; |
---|
28 | // Prevent unused label warning. |
---|
29 | if ( false ) break block; |
---|
30 | } |
---|
31 | } |
---|
32 | sout | "end" | nl; |
---|
33 | } |
---|
34 | |
---|
35 | int main() { |
---|
36 | sout | nlOff; |
---|
37 | |
---|
38 | breakTargetLabels(); |
---|
39 | sout | nl; |
---|
40 | breakSkipsUnlabelled(); |
---|
41 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.