<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Warn when manual invoking a non-virtual destructor of a class with virtual methods"
href="https://llvm.org/bugs/show_bug.cgi?id=26137">26137</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Warn when manual invoking a non-virtual destructor of a class with virtual methods
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dcheng@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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:
<a href="https://crbug.com/577478">https://crbug.com/577478</a>.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>