fix Issue 17491 - Compiles on invalid: *&s.init.var is not an lvalue #6893
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.
Same as #6892, but with added test case.
The idea here is that, the optimizer can simplify:
S(42).var
->42
, and*&S(42).var
->S(42).var
But it is not able to (in one pass) go from:
*&S(42).var
->42
Because of this, the compiler accepts an assignment to non-lvalue as valid code because it hasn't sufficiently determined that the LHS is infact a constant literal.
The first commit is a prerequisite for this fix.
PowExp.optimize
is code that I wrote a few years back, and fixing 17491 exposed a hidden bug in them.Fixes dmd bug: https://issues.dlang.org/show_bug.cgi?id=17491
Fixes gdc bug: https://bugzilla.gdcproject.org/show_bug.cgi?id=151