-
-
Notifications
You must be signed in to change notification settings - Fork 378
improve definition of assign expression behaviour #2881
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,18 @@ $(GNAME AssignExpression): | |
occurs. The resulting expression is a modifiable lvalue. | ||
) | ||
|
||
$(P Operands of an assign expression are evaluated before the assign expression. | ||
The expression) | ||
-------------- | ||
a op= b | ||
-------------- | ||
|
||
is exactly the same as: | ||
|
||
-------------- | ||
a = a op b | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that the point? Whether or not
=>
That is, unless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then in most cases, |
||
-------------- | ||
|
||
$(UNDEFINED_BEHAVIOR | ||
If either operand is a reference type and one of the following: | ||
$(OL | ||
|
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.
@thewilsonator I suppose this would be a more accurate wording:
Which would address the question of side effects.
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.
Is it though? I thought it would be rewritten to
auto [ref] __tmp = a; __tmp = __tmp op b;
, the number of evaluation is important.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, I thought that was clear. Yeah, I guess it makes sense to specify this more accurately.
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.
One exception to that rewrite though is array concatenation.
Because evaluating
a
changes its underlying size, so it would instead be conceptuallyUnless I'm failing to see a disconnect between the evaluation of
a
and extending its size for the concatenation.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.
Why does evaluating
a
change its size ? Isn't the size change part of the execution of~=
, not the evaluation of operands ?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.
Because in
a op= b
, operanda
can only be evaluated once. Separating the size change from the evaluation means you'll have to compute it twice.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.
Nope, this is definitely wrong, see e.g. https://github.com/dlang/dmd/blob/a9e5b0db723f8edaf80df28f93257edf06d3f17b/test/runnable/evalorder.d#L59-L61.
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.
I translated that test for eval order to the
~=
operator:DMD fails with [2,11,7]
gdc 10.2 fails with core.exception.OutOfMemoryError.
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.
Excellent, that means garbage is passed as the destination slot in
append(&dst, mul11ret3(val))
instead of the address toval
.