Bug 688 – Implicit function template match doesn't work for classes
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2006-12-14T00:31:00Z
Last change time
2014-02-15T13:20:47Z
Assigned to
bugzilla
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2006-12-14T00:31:47Z
IFTI works fine for structs in the case below, but doesn't work for classes.
Here's the code:
-----
// With DMD 0.177
// Error:
// template xxx.bar_class(T) does not match any template declaration
// template xxx.bar_class(T) cannot deduce template function from argument
// types (FooClass,FooClass)
class FooClass(T) { T data; }
struct FooStruct(T) { T data; }
void bar_struct(T)(FooStruct!(T) a) {}
void bar_class(T)(FooClass!(T) a) {}
void main()
{
auto C = new FooClass!(double);
FooStruct!(double) S;
bar_struct(S); // works
bar_class!(double)(C); // works
bar_class(C); // does not work
}
Comment #1 by wbaxter — 2006-12-17T19:53:42Z
Here's another manifestation of what is probably the same bug:
is(Type id:specialization) doesn't work for classes either.
Here's the previous example with the is test added too:
----------
class FooClass(T) { T data; }
struct FooStruct(T) { T data; }
void bar_struct(T)(FooStruct!(T) a) {}
void bar_class(T)(FooClass!(T) a) {}
template base_type(S) {
static if ( is(S T : FooStruct!(T)) ) {
alias T base_type;
}
else static if ( is(S T : FooClass!(T)) ) {
alias T base_type;
}
else {
static assert(0, "Unknown type");
}
}
void main()
{
auto C = new FooClass!(double);
FooStruct!(double) S;
bar_struct(S); // works
bar_class!(double)(C); // works
bar_class(C); // does not work
alias base_type!(FooStruct!(double)) sbase;//good
alias base_type!(FooClass!(double)) cbase;//no good
}