[llvm-bugs] [Bug 26137] New: Warn when manual invoking a non-virtual destructor of a class with virtual methods
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jan 13 22:53:42 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26137
Bug ID: 26137
Summary: Warn when manual invoking a non-virtual destructor of
a class with virtual methods
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: dcheng at google.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Clang already has a warning (-Wdelete-non-virtual-dtor) when deleting a class
with virtual functions but a non-virtual destructor. However, this warning
doesn't trigger when the destructor is manually invoked:
$ cat test.cc
#include <stdio.h>
#include <new>
struct B {
~B() { puts("Destroying B"); }
virtual void f() = 0;
};
struct D : public B {
~D() { puts("Destroying D"); }
void f() override { }
};
int main() {
char buffer[sizeof(D)];
B* b = new (buffer) D;
b->~B(); // No warning.
B* b2 = new D;
delete b2; // Warning.
}
$ clang++ -Wall -std=c++11 test.cc
test.cc:20:3: warning: delete called on 'B' that is abstract but has
non-virtual destructor
[-Wdelete-non-virtual-dtor]
delete b2; // Warning.
^
1 warning generated.
This has already resulted in at least one real bug in Chrome:
https://crbug.com/577478.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160114/e730e304/attachment.html>
More information about the llvm-bugs
mailing list