Bug 5532 – Overloading an operator breaks when using typeof(this)

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2011-02-06T10:58:00Z
Last change time
2011-02-06T11:58:11Z
Assigned to
nobody
Creator
akb825

Attachments

IDFilenameSummaryContent-TypeSize
900test.dTest source file that displays the errant behavior.text/plain341

Comments

Comment #0 by akb825 — 2011-02-06T10:58:08Z
If you overload an operator and use tyepof(this) as the type of the parameter, the compiler will throw an error about incompatible types. See the attached d source file for an example. This can be worked around by using the struct/class name instead of typeof(this) for the parameter. If you're defining the operator in a template mixin (the case where I originally noticed the bug), you will need to pass the type as a template argument. I am using gdc 2.051 compiled against gcc version 4.5.2 on an x64 Linux system running Debian Squeeze. I initially posted this on gdc's bug tracker (https://bitbucket.org/goshawk/gdc/issue/150/overloading-an-operator-breaks-when-using#comment-362929) but they said it's likely a problem with the frontend.
Comment #1 by akb825 — 2011-02-06T11:02:12Z
Created attachment 900 Test source file that displays the errant behavior.
Comment #2 by bearophile_hugs — 2011-02-06T11:34:51Z
Reduced test case: struct Foo { void opBinary(string op)(typeof(this) other) {} } void main() { Foo() + Foo(); }
Comment #3 by bearophile_hugs — 2011-02-06T11:57:04Z
It seems a dupe of my bug 4413
Comment #4 by bearophile_hugs — 2011-02-06T11:58:11Z
*** This issue has been marked as a duplicate of issue 4413 ***