[Issue 14364] DMD should compile (correctly) SDC test0167.d
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Mar 28 11:25:38 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14364
ag0aep6g at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from ag0aep6g at gmail.com ---
(In reply to Shammah Chancellor from comment #0)
> int ret = 5;
> ret += ((ret++ == 5) ? (ret += 3) : (ret -= 11)) + ret;
> assert(ret == 23);
To arrive at 23 I guess sdc see these values:
5 + 6 + 3 + 9 = 23
ret += ((ret++ == 5) ? (ret += 3) : (ret -= 11)) + ret;
That is, sdc takes the value of the lhs before evaluating the rhs.
dmd arrives at 27 = 9 + 6 + 3 + 9, meaning it evaluates the rhs before taking
the value of the lhs.
The spec has something to say about that[1]:
> The following binary expressions are evaluated in an implementation-defined order:
>
> AssignExpression, function arguments
>
> It is an error to depend on order of evaluation when it is not specified. For example, the following are illegal:
>
> i = i++;
So, both sdc and dmd are right and the test case is "illegal". Closing as
invalid.
[1] http://dlang.org/expression.html
--
More information about the Digitalmars-d-bugs
mailing list