[Issue 5749] argument evaluation order of chained function from right
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 25 18:28:52 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=5749
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Severity|enhancement |major
--- Comment #8 from Kenji Hara <k.hara.pg at gmail.com> 2013-11-25 18:28:48 PST ---
(In reply to comment #7)
> This patch seems important.
The root issue is very similar to bug 8396. When method call is used, the side
effect of callable entity (evaluation of 'this' object + getting member
function pointer) is not ordered before the arguments evaluation.
I think this is not intended behavior. For example, this code evaluates
function arguments left-to-right.
extern (C) int printf(const char*, ...);
void main()
{
void delegate(int) foo(int i)
{
printf("i: %d\n", i);
return (a){ foo(a); };
}
auto getFunc() { return &foo; }
int i;
getFunc()(++i)(++i);
// getFunc() is evaluated before the first ++i expression,
// and getFunc()(++i) is evaluated before the second ++i expression.
}
Because l-to-r evaluation is enforced by the glue-layer code
https://github.com/D-Programming-Language/dmd/blob/7360ae8611add4dc0a89cd870a6ac6490fb2a19b/src/e2ir.c#L3706
The code was introduce by the commit:
https://github.com/D-Programming-Language/dmd/commit/80e2319878bee3bb139a20c0bc1b85b1ec04b892
If you comment out the part, above example code will be broken.
Therefore, I'll change this issue to 'wrong-code' bug.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list