Bug 5738 – error message for template mismatch could be better
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-15T03:20:00Z
Last change time
2015-06-09T05:11:41Z
Keywords
diagnostic
Assigned to
nobody
Creator
hoganmeier
Comments
Comment #0 by hoganmeier — 2011-03-15T03:20:12Z
void bla(T...)(T args)
{
foreach(idx, arg; args)
blub(idx, arg);
}
void blub(T)(short idx, T arg) // on x64, replace short with int to get a more real world case
{
}
void main()
{
bla(5, 2);
}
templ.d(4): Error: template templ.blub(T) does not match any function template declaration
templ.d(4): Error: template templ.blub(T) cannot deduce template function from argument types !()(uint,int)
templ.d(4): Error: template templ.blub(T) does not match any function template declaration
templ.d(4): Error: template templ.blub(T) cannot deduce template function from argument types !()(uint,int)
templ.d(13): Error: template instance templ.bla!(int,int) error instantiating
It wasn't obvious for me that it couldn't implicitly convert the idx argument.
Comment #1 by hoganmeier — 2011-03-15T05:26:43Z
another more cryptic example is the following:
void bla() {}
class Blub
{
U getInfo(U, alias infoFunction = bla)(uint infoname)
{
return 0;
}
uint referenceCount() const
{
return getInfo!uint(55u);
}
}
refconst.d(12): Error: template refconst.Blub.getInfo(U,alias infoFunction = bla) does not match any function template declaration
refconst.d(12): Error: template refconst.Blub.getInfo(U,alias infoFunction = bla) cannot deduce template function from argument types !(uint)(uint)
The problem is that getInfo needs to be const as well, but there's no hint whatsoever. It's hard to detect that in a big codebase.
Removing alias infoFunction from getInfo results in a slightly less cryptic (but still non-intuitiv message, but that's another issue: http://d.puremagic.com/issues/show_bug.cgi?id=4497):
refconst.d(10): Error: function refconst.Blub.getInfo!(uint).getInfo (uint infoname) is not callable using argument types (uint) const
Comment #2 by k.hara.pg — 2013-04-07T04:41:22Z
(In reply to comment #0)
[snip]
This code works with 2.063a(git head). IFTI bug might be already fixed.
(In reply to comment #1)
Compiler now reports following errors for the invalid code.
test.d(12): Error: mutable method test.Blub.getInfo!(uint).getInfo is not callable using a const object