Is DMD breaking BigInt?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 8 06:02:38 PDT 2017


On 04/07/2017 07:06 PM, Russel Winder via Digitalmars-d-learn wrote:
> factorial.d(71,15): Error: template std.bigint.BigInt.__ctor cannot deduce function from argument types !()(string) immutable

On 04/08/2017 02:18 PM, Russel Winder via Digitalmars-d-learn wrote:
> https://github.com/russel/Factorial/tree/master/D

So, factorial.d:71 is this:

----
     tuple(30, immutable BigInt("265252859812191058636308480000000")),
----

And the BigInt constructor you're trying to use there is this one [1]:

----
     this(Range)(Range s) if (
         isBidirectionalRange!Range &&
         isSomeChar!(ElementType!Range) &&
         !isInfinite!Range)
----

In order to construct an immutable object, the constructor must either 
have the `immutable` attribute, or it must be `pure` so that the object 
is known to be unique. The constructor being templated, I think `pure` 
should be inferred when possible. But when I add it explicitly, your 
code compiles, so the attribute is apparently not inferred. Looks like a 
compiler bug to me. I've filed an issue:
https://issues.dlang.org/show_bug.cgi?id=17309

It works with LDC because their BigInt doesn't have the templated 
constructor (yet, I guess).


[1] 
https://github.com/dlang/phobos/blob/df82dea9caf4a01f00734001fae62cee38ee4f4e/std/bigint.d#L64-L67


More information about the Digitalmars-d-learn mailing list