[Issue 16542] makeArray not usable with const initializer
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jan 10 08:04:41 PST 2017
https://issues.dlang.org/show_bug.cgi?id=16542
--- Comment #2 from Ryan <clumsycodemonkey at gmail.com> ---
The code below compiles and runs unless you uncomment the first case. Then it
fails on DMD 2.72.2 on mac. I ran this file with 'rdmd -unittest -main test.d'.
It fails to find a template match for the first case, but when you cast away
the const, it works fine.
-------------------------------------------
module test;
void doSomething(T)(in T initialValue)
{
import std.experimental.allocator;
import std.stdio;
pragma(msg, typeof(initialValue).stringof ~ " " ~
typeof(cast()initialValue).stringof);
//T[] t = theAllocator.makeArray!T(5, initialValue); // won't compile
T[] t2 = theAllocator.makeArray!T(5, cast()initialValue); // this one
compiles
// ... use t and t2
writeln(t2);
}
unittest
{
int i = 5;
int[3] j = [1,2,3];
doSomething(i);
doSomething(j);
}
------------------------------------------------
Thanks,
--
More information about the Digitalmars-d-bugs
mailing list