www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5532] New: Overloading an operator breaks when using typeof(this)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5532

           Summary: Overloading an operator breaks when using typeof(this)
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: akb825 gmail.com



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5532




Created an attachment (id=900)
Test source file that displays the errant behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5532


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Reduced test case:


struct Foo {
    void opBinary(string op)(typeof(this) other) {}
}
void main() {
    Foo() + Foo();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5532




It seems a dupe of my bug 4413

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5532


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 4413 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011