https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83627
Bug ID: 83627
Summary: -Wdelete-non-virtual-dtor doesn't trigger when calling
destructor by hand
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: simon.marchi at polymtl dot ca
Target Milestone: ---
The -Wdelete-non-virtual-dtor triggers only when using "delete" and not by
calling the destructor by hand. clang does:
$ clang++ test.cpp -Wall -std=gnu++11
test.cpp:25:2: warning: destructor called on non-final 'Foo' that has virtual
functions but non-virtual destructor [-Wdelete-non-virtual-dtor]
f->~Foo();
^
test.cpp:25:5: note: qualify call to silence this warning
f->~Foo();
^
Foo::
1 warning generated.
I think it makes sense to warn in that case, even though the warning is
specifically about "delete" and there's no "delete" when calling the destructor
by hand.
Here's the test program I used:
#include <iostream>
struct Foo
{
~Foo() {
std::cout << "Foo dtor" << std::endl;
}
virtual void bar();
};
struct Bar : Foo
{
~Bar() {
std::cout << "Bar dtor" << std::endl;
}
};
void Foo::bar ()
{
}
int main()
{
Foo *f = new Bar;
f->~Foo();
}