D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8844 - Warning for bug-prone operator overloading
Summary: Warning for bug-prone operator overloading
Status: RESOLVED DUPLICATE of issue 20576
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-10-17 15:46 UTC by bearophile_hugs
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-10-17 15:46:15 UTC
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.
Comment 1 Andrej Mitrovic 2012-10-18 11:28:48 UTC
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.
Comment 2 basile-z 2020-02-20 15:05:12 UTC
This is part of a more general problem that is default template parameter values are not always checked.

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