example: --------------------------------------- void doSomething(T)(in T initialValue) { T[] t = theAllocator.makeArray!T(100, initialValue); // won't compile T[] t2 = theAllocator.makeArray!T(100, cast()initialValue); // this one compiles // ... use t and t2 } ----------------------------------------- If all you are doing is copying the value, you shouldn't actually be changing initialValue, so why not make it const?
Can you add a test case please ? I suspect this report to be either either bad formulated or invalid because with DMD 2.073-b1 the following test passes: unittest { const int[] v; void test(T)(in T t) { auto a = theAllocator.makeArray(100, t); } test(v); }
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,
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cd66c0cba650d63785ccb79a115964e6472692ca fix issue 16542 https://github.com/dlang/phobos/commit/2e9271962ffbe2cdabff8fe39be3c55121de6232 Merge pull request #5028 from somzzz/issue_16542 fix issue 16542 - makeArray not usable with const initializer
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cd66c0cba650d63785ccb79a115964e6472692ca fix issue 16542 https://github.com/dlang/phobos/commit/2e9271962ffbe2cdabff8fe39be3c55121de6232 Merge pull request #5028 from somzzz/issue_16542