Types A!1 and A!1u not considered equal?

kenji hara k.hara.pg at gmail.com
Fri Oct 21 03:56:55 PDT 2011


2011/10/21 Don <nospam at nospam.com>:
> 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.

Bug 1641 is already fixed. That issue does not occur with newest dmd.

And, it is bug 3467. I have already posted dmd patch.
http://d.puremagic.com/issues/show_bug.cgi?id=3467
https://github.com/D-Programming-Language/dmd/pull/449

Kenji Hara


More information about the Digitalmars-d mailing list