On Mar 7, 11 15:16, %u wrote:
That's essentially the example that's been under discussion - though in this 
case it's a ref instead of
a temporary for the lvalue. Regardless, it's context free because a * b is by 
definition a variable
declaration, not a call to the multiplication operator. If you want it to use 
the multiplication
operator, then use parens: (a * b) = b. It's context free, because it just 
assumes one of the two and
it's _always_ that one, so there's no ambiguity. It is, _by definition_, a 
variable declaration.

Oh, I see. So is multiplication being special-cased in the grammar, or is it 
part of a more general rule
in the language?


Only statement of the form 'p*q=r' is "special-cased". Actually it's not quite fair to say it is "special-cased", just because declarations (which accepts 'p*q=r') are processed before expressions.

    import std.stdio;

    struct Foo {
        ref Foo opBinary(string x) (int a) pure nothrow {
            return this;
        }
        ref Foo opBinaryRight(string x) (int a) pure nothrow {
            return this;
        }
    }

    void main() {
        Foo a;
        int b;
        a + 1 = a;
        a * 1 = a;
        1 + a = a;
        1 * a = a;
        a + b = a;
        //a * b = a;
    }






Also, opMul is on its way to deprecation. binaryOp should be used for 
overloading the multiplication
operator.

Whoa! I did not know that; thanks.

Reply via email to