On Thursday, 23 October 2014 at 18:57:33 UTC, Ali Çehreli wrote:
On 10/22/2014 11:37 PM, Jonathan M Davis wrote:

> x = x;
>
> which is so obviously wrong that I don't know how much of
anyone could
> make that mistake. But simply making it illegal to assign a
variable to
> itself would solve that problem, and that arguably should be
done, since
> it's a essentially a no-op.

Steve said the same thing and it's true for fundamental types but just to annoy you two, assignment can have side effects. :)

import std.stdio;

struct X
{
    X opAssign(X that)
    {
        writeln("side-effect!");
        return this;
    }
}

void main()
{
    auto x = X();
    x = x;
}

LOL. Yeah. In that case, it wouldn't be a no-op and shouldn't be an error, but in any assignment where the operator wasn't overloaded by that type or any of its member variables (directly or indirectly), it _is_ a no-op and should arguably result in an error.

- Jonathan M Davis

Reply via email to