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 ?