[Bug c++/42992] New: [C++0x] =default erases virtual declaration of a destructor.
albrt2000 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Feb 7 11:24:00 GMT 2010
Hello,
Following code :
#include <iostream>
struct A {
virtual ~A()=default;
};
struct B : public A {
virtual ~B() {
std::cout << "B destructor\n";
}
};
int main() {
B* b = new B;
A* pA = b;
delete pA;
return 0;
}
outputs nothing, B destructor is not called as if A destructor was not
considered as virtual.
However, following code works fine :
#include <iostream>
struct A {
virtual ~A();
};
A::~A()=default;
struct B : public A {
virtual ~B() {
std::cout << "B destructor\n";
}
};
int main() {
B* b = new B;
A* pA = b;
delete pA;
return 0;
}
It outputs "B destrucor".
Having to separate virtual declaration from default definition seems to be out
of spec.
Bug found with MinGW/gcc 4.4.1..
Compilation command :
mingw32-g++.exe -Wall -fexceptions -Wmain -pedantic -W -g -std=c++0x -c
main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\TestCpp.exe obj\Debug\main.o
Best Regards
Albert.
--
Summary: [C++0x] =default erases virtual declaration of a
destructor.
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: albrt2000 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42992
More information about the Gcc-bugs
mailing list