August 12, 2005
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

1 2 3 4 5 6 7 8 9
Next ›   Last »