<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59032>59032</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
false positive: cppcoreguidelines-virtual-class-destructor for templated base and derived class if derived class has another virtual function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kwasniok
</td>
</tr>
</table>
<pre>
Heads up: This bug seems to be very specific.
## Version (14.0.6)
```
LLVM version 14.0.6
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: haswell
```
Unfortunately, I could not get my hands on a newer version.
## Related
- #51759
- #51254
## How to Reproduce
```cpp
// test.cpp
template <class>
struct A {
virtual ~A() = default;
};
template <class T>
struct B : public A<T> {
~B() override = default;
virtual void f() = 0;
};
```
running:
```bash
clang-tidy --checks="cppcoreguidelines-virtual-class-destructor" test.cpp -- -std=c++20
```
results in:
```
1 warning generated.
test.cpp:8:8: warning: destructor of 'B' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
struct B : public A<T> {
^
test.cpp:8:8: note: make it public and virtual
struct B : public A<T> {
^
```
## Why This Bug is So Specific
The false positive vanishes in either of the following cases:
- base class `A` is not a template
- derived class `B` is not a template
- derived class `B` does not have another (`public` or `protected`) virtual member function
- adding the keyword `virtual` to `~B`, but this triggers `cppcoreguidelines-explicit-virtual-functions` instead
## Further Observation
`clang++ -Werror -Wnon-virtual-dtor -c test.cpp` compiles without errors (and so does `g++`).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVt-PozYQ_mvIywhEIJDkgYdks6utetVVd3u3jyeDB3DXwcg2yaZ_fcf8SDZpKvVaiV2wGc988803Q3LFT9kzMm6ga714Ay-1MJB3FRjEvQGrIEc4oD6BabEQpSgCL9x54Wb8H8V0wXfURqgGvGg1XwRhkHrRejRIw_HqlwCfPn3_zTns7Ufj8dXn1oq9-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