The attached test case leads to this error: [EMAIL PROTECTED] Orfeo]$ g++ main.ii ../../Orfeo/A.h:3: warning: inline function A::~A() used but never defined /tmp/cc2W2kUK.o(.gnu.linkonce.t._ZN1BI1AED1Ev[B<A>::~B()]+0xf): In function `B<A>::~B()': : undefined reference to `A::~A()' collect2: ld returned 1 exit status
This is a very simplified model of a bug which I have found when using the STL vector template, which explicitly invokes a destructor via p->~T(). The problem is that class A does not define an explicit destructor, but the class B<A> needs it. This is a regression since 3.4.2 (or at least the Fedora Core version gcc-3.4.2-6.fc3). Running that on the same code, no destructor call ~A() is generated in ~B(). Presumably the compiler deduces that the template class T(=A) has no nontrivial destructor in this case and so optimizes out the call t->~T(); [Presumably an empty stub could be generated, but where? In the present example it is not generated since the filename for the #pragma implementation (main.cc) does not match that for the #pragma interface (A.h). You might add an implementation file A.cc with a #pragma implementation, but this does not help unless it contains an explicit reference to ~A. Otherwise it doesn't know that any such destructor is needed. The destructor would have to be generated at the point of use, even though this may lead to some duplication between modules, since there seems to be no way of deducing the "correct" place to put it.] -- Summary: [4.0 Regression] Another way to generate "inline function ‘A::~A()’ used but never defined" errors Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: prw at ceiriog1 dot demon dot co dot uk CC: gcc-bugs at gcc dot gnu dot org,prw at ceiriog1 dot demon dot co dot uk GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21306