Bug 3935 – opBinary is instantiated with "="

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-03-11T16:50:00Z
Last change time
2014-02-15T02:44:18Z
Keywords
patch, spec, wrong-code
Assigned to
nobody
Creator
hoganmeier

Comments

Comment #0 by hoganmeier — 2010-03-11T16:50:40Z
This is really strange behavior. It gets even stranger over time. It once started with Vector2f _pos = Vector2f(0.f, 0.f); yields: Error: template instance opBinary!("=") matches more than one template declaration Now I can't seem to reproduce it anymore. But in a bigger project, with the following code: Vector2 opBinary(string op, U:Vector2)(U v) { pragma(msg, "opBinary!"~op); } I get several instantiations with opBinary!= Even though http://www.digitalmars.com/d/2.0/operatoroverloading.html#Binary clearly states that "=" isn't overloadable which totally makes sense since there is http://www.digitalmars.com/d/2.0/operatoroverloading.html#Assignment
Comment #1 by bearophile_hugs — 2010-03-11T18:06:04Z
When you submit a bug it's better to show a minimal but complete program that shows your problem. This shows the situation (I think it's cute, an undocumented operator overload): struct Foo { void opBinary(string op)(Foo other) { pragma(msg, "op: " ~ op); } } void main() { Foo f; f = f; }
Comment #2 by hoganmeier — 2010-03-12T13:50:34Z
found the cause: if opAssign isn't present but opBinary is, opBinary is instantiated with "=". This could probably be fixed by replacing opover.c:458 with if (!s && !s_r && op != TOKequal && op != TOKnotequal && op != TOKassign) The question is if opAssign is really meant to stay.
Comment #3 by hoganmeier — 2010-07-28T06:41:55Z
Sorry, just giving one line isn't good practice, so: =================================================================== --- opover.c (revision 589) +++ opover.c (working copy) @@ -474,7 +474,7 @@ Objects *targsi = NULL; #if DMDV2 - if (!s && !s_r && op != TOKequal && op != TOKnotequal) + if (!s && !s_r && op != TOKequal && op != TOKnotequal && op != TOKassign) { /* Try the new D2 scheme, opBinary and opBinaryRight */ if (ad1)
Comment #4 by bugzilla — 2010-08-26T22:53:32Z