D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3177 - constrained template reverse operator overload prohibits use of non-reverse overloads
Summary: constrained template reverse operator overload prohibits use of non-reverse o...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-15 02:12 UTC by Christian Kamm
Modified: 2015-06-09 01:28 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 Christian Kamm 2009-07-15 02:12:46 UTC
struct imaginary {}

struct complex {
    complex opAdd(complex s) { return this; }
    complex opAdd_r(T)(T t) if (is(T == imaginary)) { return this; }
}

void main() {
    complex s;
    s = s + s;
}

yields the error

Error: template complex.opAdd_r(T) if (is(T == imaginary)) does not match any function template declaration
Error: template complex.opAdd_r(T) if (is(T == imaginary)) cannot deduce template function from argument types !()(complex)

even though opAdd_r is only defined for T == imaginary. 

This may be by design: calling a constrained template function with template arguments that don't satisfy the constraints also doesn't give you an "undefined identifier" error, but rather a message like the one above, mentioning the function template declaration. However, it makes using constrained templates for operator overloading impossible.

I'd expect a non-matching template operator overload to be ignored if there are other matches.
Comment 1 Andrej Mitrovic 2012-01-21 18:01:32 UTC
Can't reproduce in 2.057, likely fixed by now.