llvm / llvm/llvm-project

[clang-tidy] cppcoreguidelines-virtual-class-destructor prints misleading diagnostics

Open
#224,686 1 comment 0 reactions 0 assignees View on GitHub
clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c++
class a {

protected:
virtual ~a() = default;
};
```
--checks=cppcoreguidelines-virtual-class-destructor for clang-tidy, nothing in particular needed for Clang. Linebreaks necessary. https://godbolt.org/z/xaYxEMvMb

Output:
```
:1:7: warning: destructor of 'a' is protected and virtual [cppcoreguidelines-virtual-class-destructor]
1 | class a {
| ^
:1:7: note: make it protected and non-virtual
1 | class a {
| ^
```
Expected: Point to the dtor, and/or the word `protected`. Pointing to the class head makes me think the dtor is defaulted, and the dtor I added ended up as part of a different class or something.

Contributor guide

Open the contributing guide

Research direction

Reproduce the example with clang-tidy's cppcoreguidelines-virtual-class-destructor check, using the linked Compiler Explorer case and the required line breaks. Trace how the diagnostic and note locations are selected; done means they point to the destructor and/or `protected` rather than the class head, with the misleading wording corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.