struct S(T : T*) {
T t; // t is supposed to be of type 'int*', but it's of type 'int', why?
}
void main() {
int x = 123;
S!(int*) s;
static assert(is(typeof(s.t) == typeof(&x)));
}
上述代码无法编译。
奇怪的是,下面的代码可以成功编译:
struct S(T : int*) {
T t;
}
void main() {
int x = 123;
S!(int*) s;
static assert(is(typeof(s.t) == typeof(&x)));
}
我不理解这种行为。希望能够给出解释。
struct S(T:void*)
。 - ratchet freaks.t =&x
是不起作用的,我会得到“错误:无法将类型为int *的表达式(&x)隐式转换为int”。所以我猜这是DMD的一个bug? - Arlenis
表达式,确实存在这个问题。我只是指出这些断言本身是不正确的。 - Jonathan M Davis