Bug 3613 – enforce cannot be called with template parameters and compile.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-12-12T22:00:00Z
Last change time
2014-02-14T20:35:54Z
Keywords
rejects-valid
Assigned to
nobody
Creator
sandford
Comments
Comment #0 by sandford — 2009-12-12T22:00:37Z
The following test case:
enforce!(bool,"hi",5)(true, "hi");
results in an error:
Error: template instance enforce!(bool,"hi",5) matches more than one template declaration, enforce(T,string file = __FILE__,int line = __LINE__) and enforce(T,string file = __FILE__,int line = __LINE__)
using DMD 2.037.
Comment #1 by rsinfu — 2010-10-08T01:36:38Z
The problem seems to be surprisingly deep... Here're reduced test cases.
This code compiles fine:
--------------------
void main()
{
test!int(-1, 10);
test!int(-1, "");
}
void test(T)(T v, int) {}
void test(T)(T v, string) {}
--------------------
While the following doesn't:
--------------------
void main()
{
test!int(-1, [10]); // (4)
test!int(-1, "");
}
void test(T)(T v, int[]) {} // (6) just changed from int -> int[]
void test(T)(T v, string) {} // (7)
--------------------
% dmd -o- -c test.d
test.d(4): Error: template test.test(T) test(T) matches more than one template declaration, test.d(6):test(T) and test.d(7):test(T)
Comment #2 by andrej.mitrovich — 2012-10-21T19:29:32Z