Bug 5709 – template instantiation fails with extra non-mutable class parameter
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2011-03-05T18:35:00Z
Last change time
2012-04-23T18:22:21Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2011-03-05T18:35:26Z
This program fails to compile
import std.traits;
class C
{
}
void func1(S)(in S str, immutable C a = null)
if(isSomeString!S)
{
func2(str, a);
}
void func2(S)(in S str, immutable C a = null)
if(isSomeString!S)
{
}
void main()
{
func1("hello world");
func2("hello world");
}
giving this error:
q.d(10): Error: template q.func2(S) if (isSomeString!(S)) does not match any function template declaration
q.d(10): Error: template q.func2(S) if (isSomeString!(S)) cannot deduce template function from argument types !()(const(immutable(char)[]),immutable(C))
q.d(20): Error: template instance q.func1!(string) error instantiating
Removing the template constraints has no effect. Thus far, anything that I change immutable C a to anything other than a const C, _does_ compile, but it fails to compile as long as it's const or immutable. The fact that it's a default parameter seems to have no effect. If pass it a new C() instead of null, that has no effect. If I change the func2 call in func1 to func2!S, then it compiles just fine. But for some reason, when the second class parameter is there and it's not mutable, the template instantiation fails to determine the correct type of S for the inner instantiation, and you're forced to tell it.
So, this bug is just plain weird, and it _can_ be gotten around, but it's _definitely_ a bug.