Recursive template instantiation
Jack Applegame via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 13 07:26:30 PDT 2017
I'm pretty sure that this code should compile
(https://dpaste.dzfl.pl/cf1e1ee6ef4b):
struct A(T) {
~this() {
char[T.sizeof] data;
}
}
struct B(T) {
A!T foo;
}
struct C {
B!C bar;
}
void main() {
C c;
}
But it doesn't:
/d300/f416.d(3): Error: struct f416.C no size because of forward
reference /d300/f416.d(12): Error: template instance f416.B!(C)
error instantiating
Notice that the same C++ code compiles without problems:
template<typename T> struct A {
~A() {
char data[sizeof(T)];
}
};
template<typename T> struct B {
A<T> foo;
};
struct C {
B<C> bar;
};
int main() {
C c;
}
A simple recursion is compiled successfully
(https://dpaste.dzfl.pl/5a8ff73bfa88):
struct A(T) {
~this() {
char[T.sizeof] data;
}
}
struct C {
A!C bar;
}
void main() {
C c;
}
More information about the Digitalmars-d-learn
mailing list