-
-
Notifications
You must be signed in to change notification settings - Fork 672
fix Issue 12486 - Function returning struct isn't called if enum of its result is accessed
#8013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dlang-bot
merged 2 commits into
dlang:master
from
FeepingCreature:fix/12486-dont-discard-expression-on-enum-access
Apr 8, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,18 @@ | ||
| module test12486; | ||
|
|
||
| struct S { enum a = 1; } // or `const` but not for all types | ||
|
|
||
| S f(ref int i) | ||
| { | ||
| ++i; | ||
| return S(); | ||
| } | ||
|
|
||
| void main() | ||
| { | ||
| int i = 2; | ||
| assert(f(i).a == 1); | ||
| // ensure that f(i) was actually called, even though | ||
| // a is a statically known property of the returned type | ||
| assert(i == 3); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FeepingCreature - you could also use
hasSideEffects(e)(ore.hasSideEffects()if you prefer UFCS). When having an initial glance at the implementation, it didn't seem like it was a strong enough guarantee, but having a closer look, only strongly pure functions would have their calls omitted here. Which is harmless.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell,
pure void foo() { while (true) { } }is strongly pure, but must under no circumstances be optimized away. That exact case was what triggered this bug in the first place.Pure expressions can be reduced from two to one, but only trivial expressions can be reduced from one to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, bugger those looping pure functions. :-)
Yep, makes sense, and LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FeepingCreature - For brownie points, you can add a comment with a link to the bugzilla reference.