http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52746
Bug #: 52746 Summary: [4.7 Regression] Explicit virtual destructor call replaced by direct call in template function Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: loic.yh...@gmail.com Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu #include <stdio.h> class A { public: virtual ~A() { printf("~A()\n"); } }; class B : public A { public: virtual ~B() { printf("~B()\n"); } }; template<int> void test() { B * b = new B; A * a = reinterpret_cast<A*>(b); a->~A(); ::operator delete(b); } int main(void) { test<0>(); return 0; } Compile with g++ With 4.6.3, it outputs "~B()" and "~A()", since a->~A() is the expected virtual call, which will target B::~B() in this case. With 4.7.0, it only outputs "~A()", a->~A() is a direct call to A::~A(). The bug doesn't happen if test() function is not a template.