<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62685>62685</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor is bogus
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tiagomacarios
</td>
</tr>
</table>
<pre>
The following code will trigger clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor
https://godbolt.org/z/dxdYe1zc8
```
struct B{};
struct D : B{};
void fun()
{
B* b = new D{};
delete b;
}
```
<details>
<summary>Error output</summary>
```
<source>:8:5: warning: Destruction of a polymorphic object with no virtual destructor [clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor]
delete b;
^~~~~~~~
<source>:7:12: note: Conversion from derived to base happened here
B* b = new D{};
^~~~~~~
<source>:8:5: note: Destruction of a polymorphic object with no virtual destructor
delete b;
^~~~~~~~
1 warning generated.
```
</details>
Looking at the code in [DeleteWithNonVirtualDtorChecker.cpp](https://github.com/llvm/llvm-project/blob/64f1fda29e2dd133c84f23474e29de02d7ed392d/clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp#L73-L86) it looks like we are missing a check for `DerivedClass->isPolymorphic()`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE-P6zQQ_zTuZbRVMm7-HXJom-b0hJBAII6OPUnMunFkOy27Bz47ctqlsOyixyNqk1Yznszvz4zwXg8TUc2yA8uajVjCaF0dtBjsWUjhtPWbzqqX-seRoLfG2KueBpBWEVy1MRCcHgZyII2YhicxCfPySu5JmHkUWzmbxcfvtiFDgX7WYfzOTj9pFxZhmmAdSxqW7McQZs_4nmHLsB2s6qwJW-sGhu0rw1b9pn6h9FWWt3SWJ_fP-tcHt8gAB1YcWNEwfrhn_TXYAOP7T1IuVivol4lhybC6R4p7CgDAgeEeOmC8gYmu0LyrAmoFB92jbtF82On9zo-KgtDGM356vIXxo1_OZ-FeGD-dnLMO7BLmJTB-ZNg-Yn-r9e4F_Ojt4iTFNL4vGd9nEfhVuElPQ_zZ0I0SbSewPQiYrXk5WzePWoLtfiUZ4KrDCJOFy00oUPcz1gHLDt8qddY8wP6DspWB7PT77foQTcH4PsWIYbKB4vNopws5H6H0zp5BkdMXUhAsdMITjGKeaSIFIzn6ej0f158d_Tu9b_38P24_c9NH1KRvksJAEzkRSG0_c0QcoHd-u92_WPscS4gAYaTbUOspSvyZhseR5DO5rZznKCeW7yZXh3HpttKeGbbGXN4eT7OzETzDtjO2Y9jmuz7tlcCKUKmUc1nueuS7YkdYKUpQFaR4hYphu9otFtLx4A9BBC33d_MxbO8teYbt13SN_EvBn76UOcMKdABj7bMHo58JrgTCEZy19ysrIOM56KPr86S5eetohPdPjJ-0__4h7n115MlG1VxVvBIbqtO85FVaFlm-GWuOO5nssorLFKtepJXMyzTjeZmlRd9X1UbXmCBPshTTKkWeb1EIkkiVyvOElzvJdgmdhTbbyGhcjhvt_UJ1jnmZbYzoyPh1jyNGV69BhhjXuqtXFbpl8GyXGO2Df1QJOhiqv3GoQXvo7LD4zeJM_Z_dsDYZpVtB_BEAAP__kIsLTg">