https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850
Bug ID: 104850 Summary: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kirshamir at gmail dot com Target Milestone: --- The following code is rejected as trying to use incomplete type, while when the actual use would actually appear the type would be complete: template<typename T> struct uptr { uptr(nullptr_t) {} ~uptr() { delete (new T); } }; class A { public: A(); ~A(); private: class B; uptr<B> m_b = nullptr; // the dtor of uptr tries to be instantiated here }; If we change the initialization of: uptr<B> m_b = nullptr; To: uptr<B> m_b {nullptr}; The destructor instantiation is delayed, till ~A() is seen, and the code can be compiled. See: https://stackoverflow.com/questions/71397495/why-does-default-member-initializer-request-instantiation-of-unique-ptr-destru