This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52746] New: [4.7 Regression] Explicit virtual destructor call replaced by direct call in template function
- From: "loic.yhuel at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 28 Mar 2012 00:22:18 +0000
- Subject: [Bug c++/52746] New: [4.7 Regression] Explicit virtual destructor call replaced by direct call in template function
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: loic.yhuel@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.