On 21.10.2011 02:31, Tobias Brandt wrote:
Consider the following program:
class A(uint N) {}
void foo(uint N)(A!N) {}
void main()
{
auto a = new A!1; // compiles
foo(new A!1); // error
foo(new A!1u); // compiles
foo(cast(A!1u) A!1) // compiles, but may
// crash at runtime
assert(typeid(new A!1) == typeid(new A!1u)) // compiles, fails at runtime
}
The second line in main gives the following error:
Error: cannot implicitly convert expression (new A) of type
test.A!(1).A to test.A!(N).A
Adding the 'u' makes the code compile without errors. Explicitly
instantiating foo with !1 or !1u does not change anything.
From the first line, it is clear that instantiating A!1 is not the
problem. Apparently A!1 and A!1u are considered distinct types,
although the template parameter must in both cases be of type uint
and have value 1 and thus be identical.
What's going on here?
It's a bit similar to bug 1641.