1
D在隱式函數實例化過程中丟棄頂層數組的常量,並在明確函數實例化時將其保留。 考慮代碼: 在隱式函數實例化期間數組常量丟棄
// main.d
import std.stdio;
void foo(T)(T val)
{
writeln(typeid(T));
}
void main()
{
const int[] arr;
writeln(typeid(arr)); // actual type
foo(arr); // implicit instantiation
foo!(typeof(arr))(arr); // explicit instantiation
}
...和D中的輸出:
$ dmd main.d && ./main
const(const(int)[])
const(int)[]
const(const(int)[])
As you can see, top level const was lost in case of implicit instantiation. Is this bug, feature or my misunderstanding ?