www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8844] New: Warning for bug-prone operator overloading

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

           Summary: Warning for bug-prone operator overloading
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



struct Foo {
    Foo opBinary(string op="-")(Foo f) {
        return Foo();
    }
}
void main() {
    auto Foo = Foo() + Foo();
}


Compiles and run with no errors, dmd 2.061alpha, because "-" is a default
argument for the op template argument, so that code is formally correct. But
I'd like a warning here (or an error?), because I think such code is bug-prone.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 17 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8844


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



11:28:48 PDT ---
Technically it's still callable:

auto Foo = Foo().opBinary(Foo());

But I don't know why someone would explicitly call opBinary without operators.

Making it an error could help catch bugs though. +1 from me.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 18 2012