-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is patch for issue no 192 'no error on missing defaut in non-fin…
…al switches' It check for LabeledStatements with "default" label and sets flag to indicate such statement. If flag is already set and such statement found it reports error. No Default statement found then also reports error. nested cases is also handled. Changes in file : libd/src/d/semantic/flow.d New files : tests/test0184.d tests/test0185.d tests/test0186.d tests/test0187.d
- Loading branch information
1 parent
a0cfe4a
commit d3ab7a2
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//T compiles:no | ||
//T retval:0 | ||
//T has-passed:yes | ||
// Tests multiple default in non-final switches | ||
|
||
int main() { | ||
int x = 10; | ||
switch(x) { | ||
case 0: | ||
return 1; | ||
case 2: | ||
return 2; | ||
default: | ||
return 5; | ||
default: | ||
return 7; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//T compiles:yes | ||
//T retval:0 | ||
//T has-passed:yes | ||
// Tests nested switch | ||
int main() { | ||
int x = 10; | ||
switch (x) { | ||
case 1 : | ||
switch (x) { | ||
default : | ||
break; | ||
} | ||
break; | ||
case 2 : | ||
switch (x) { | ||
default : | ||
break; | ||
case 1 : | ||
switch (x) { | ||
default : | ||
break; | ||
} | ||
break; | ||
} | ||
break; | ||
|
||
default : | ||
break; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//T compiles:no | ||
//T retval:0 | ||
//T has-passed:yes | ||
// Tests nested default for no error on missing defaut in non-final switches | ||
int main() { | ||
int x = 10; | ||
switch(x) { | ||
case 1 : | ||
switch (x) { | ||
case 1 : | ||
break; | ||
} | ||
case 2 : | ||
switch (x) { | ||
default : | ||
break; | ||
} | ||
default : | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//T compiles:no | ||
//T retval:0 | ||
//T has-passed:yes | ||
// Tests missing default in non-final switches | ||
|
||
int main() { | ||
int x = 10; | ||
switch(x) { | ||
case 0: | ||
return 1; | ||
case 2: | ||
return 2; | ||
} | ||
} | ||
|