This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52746] New: [4.7 Regression] Explicit virtual destructor call replaced by direct call in template function


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]