-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4790 from 9rnsr/fix14747
Issue 14747 - compiler insists on unnecessary return statement
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
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,31 @@ | ||
| // REQUIRED_ARGS: -o- | ||
| // PERMUTE_ARGS: -w | ||
|
|
||
| int foo(Args...)() | ||
| { | ||
| int x; | ||
|
|
||
| foreach (arg; Args) | ||
| { | ||
| static if(is(arg == int)) | ||
| { | ||
| return 0; | ||
| } | ||
| static if(is(arg == long)) | ||
| { | ||
| // fallthrough | ||
| ++x; // this statement might be unreachable, but | ||
| // UnrollStatement does not warn that. | ||
| } | ||
| } | ||
| // no return | ||
| } | ||
|
|
||
| void main() | ||
| { | ||
| auto r1 = foo!(int)(); // return | ||
| auto r2 = foo!(int, long)(); // return -> fallthrough (it's unreachable) | ||
| auto r3 = foo!(long, int)(); // fallthough -> return | ||
| static assert(!__traits(compiles, foo!(long)())); // fallthough | ||
| static assert(!__traits(compiles, foo!(long, long)())); // fallthough -> fallthough | ||
| } |