| Issue |
184184
|
| Summary |
[clang-tidy] Extend `cppcoreguidelines-virtual-class-destructor` or create a new check
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
unterumarmung
|
In the docs, this check claims to implement the C.35 guideline from the C++ Core Guidelines:
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual>
However, it currently only implements the first of the two enforcement rules:
> **Enforcement**
> 1) A class with any virtual functions should have a destructor that is either public and virtual or else protected and non-virtual.
> 2) If a class inherits publicly from a base class, the base class should have a destructor that is either public and virtual or else protected and non-virtual.
Given the demand for a rule similar to rule (2) from the C++ Core Guidelines (https://github.com/llvm/llvm-project/issues/183101) and the discussion here: https://github.com/llvm/llvm-project/pull/183384, it makes sense to implement such a check either as an extension of the existing one or as a new check.
Personally, I think rule (1) is more relevant in most code bases, because having a non-virtual destructor in a class with virtual functions is, in most (if not all) cases, a bug. Rule (2) is more opinionated, because there are legitimate use cases of inheritance where the base type is not intended to be used polymorphically (CRTP, mixins, etc.), which would make this check quite noisy.
Based on that, if rule (2) is implemented as part of `cppcoreguidelines-virtual-class-destructor`, I suggest adding it as an **opt-in option** (disabled by default).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs