August 12, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to AJG Attachments: | AJG schrieb:
>
>>http://www.digitalmars.com/d/statement.html#expression
>># Expressions that have no effect, like (x + x), are illegal in
>># expression statements.
>
>
> Why is it assumed that expression has no effect? x could have + overloaded. If so, is it still illegal?
An overloaded commutative binary operator that changes an operant is at the very least a questionable style.
As currently documented an overloaded opAdd without side effects - neglecting the allocation of memory for the return value - is illegal. If there could be any side effects - e.g. if(..) throw ... - the expression would be legal.
Note: DMD-0.129 doesn't enforce this rule
Thomas
|
Copyright © 1999-2021 by the D Language Foundation