Warn about do nothing expressions?

Frustrated Who at where.com
Sun Mar 30 09:54:01 PDT 2014


On Saturday, 29 March 2014 at 17:29:51 UTC, MattCoder wrote:
> On Saturday, 29 March 2014 at 16:31:48 UTC, Frustrated wrote:
>> On Friday, 28 March 2014 at 19:57:13 UTC, MattCoder wrote:
>>> On Friday, 28 March 2014 at 19:35:22 UTC, Frustrated wrote:
>>>> which means, i = is the previous value of j(before 
>>>> increment).
>>>> This should hold true when j is an alias for i.
>>>
>>> In this case: i = i++;  Means:
>>>
>>> "i" is incremented by one, but the value assigned in "i" is 
>>> the
>>> previous one. That's it.
>>>
>>> For me there's nothing wrong here.
>>>
>>> Matheus.
>>
>>
>> One thing you are getting wrong/leaving out is that i++, even 
>> in an assignment, increments i.
>
> I see your pain pal... so I took a look around:
> http://dlang.org/expression.html
>
> And according the page above:
>
> "Expressions
>
> C and C++ programmers will find the D expressions very familiar,
> with a few interesting additions.
>
> Expressions are used to compute values with a resulting type.
> These values can then be assigned, tested, or ignored.
> Expressions can also have side effects.
>
> Order Of Evaluation
>
> The following binary expressions are evaluated in strictly
> left-to-right order:
> [i]
> OrExpression, XorExpression, AndExpression, CmpExpression,
> ShiftExpression, AddExpression, CatExpression, MulExpression,
> PowExpression, CommaExpression, OrOrExpression, AndAndExpression
> [/i]
>
> 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++;"
>
> Matheus.

My only point is that monarch was wrong ;) Trying to justify how 
dmd does it is like trying to prove your conclusion by stating it 
as a hypothesis. Regardless if the correct behavior is to 
increment i(which I think it should) or for it to be illegal, the 
wrong behavior is to leave i unchanged. Luckily I'd never write 
such a statement but I wonder if there are more complex cases 
that produce wrong behavior?




More information about the Digitalmars-d mailing list