Try clang++ and g++, same result for both.
fatal error: recursive template instantiation exceeded maximum depth
template<class T>
struct Bar {
~Bar() {
if (ptr) { delete ptr; }
}
Bar<Bar<T>> * ptr{nullptr};
};
int main() { Bar<void> obj; }
But ctor version compiles without error:
template<class T>
struct Bar {
Bar() {
if (ptr) { delete ptr; }
}
Bar<Bar<T>> * ptr{nullptr};
};
int main() { Bar<void> obj; }
What's the problem with dtor version?