[PATCH] D126891: [clang-tidy] The check should ignore final classes
Balázs Benics via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 21 02:06:02 PDT 2022
This revision was automatically updated to reflect the committed changes.
steakhal marked an inline comment as done.
Closed by commit rGd9afb8c3e8fd: [clang-tidy] cppcoreguidelines-virtual-class-destructor should ignore final… (authored by steakhal).
Changed prior to commit:
https://reviews.llvm.org/D126891?vs=435054&id=438599#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126891/new/
https://reviews.llvm.org/D126891
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -320,3 +320,22 @@
#undef XMACRO
#undef CONCAT
} // namespace macro_tests
+
+namespace FinalClassCannotBeBaseClass {
+class Base {
+public:
+ Base() = default;
+ virtual void func() = 0;
+
+protected:
+ ~Base() = default;
+};
+
+// no-warning: 'MostDerived' cannot be a base class, since it's marked 'final'.
+class MostDerived final : public Base {
+public:
+ MostDerived() = default;
+ ~MostDerived() = default;
+ void func() final;
+};
+} // namespace FinalClassCannotBeBaseClass
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -165,6 +165,12 @@
Fixed an issue when there was already an initializer in the constructor and
the check would try to create another initializer for the same member.
+- Fixed a false positive in :doc:`cppcoreguidelines-virtual-class-destructor
+ <clang-tidy/checks/cppcoreguidelines-virtual-class-destructor>` involving
+ ``final`` classes. The check will not diagnose classes marked ``final``, since
+ those cannot be used as base classes, consequently, they can not violate the
+ rule.
+
- Fixed a crash in :doc:`llvmlibc-callee-namespace
<clang-tidy/checks/llvmlibc/callee-namespace>` when executing for C++ code
that contain calls to advanced constructs, e.g. overloaded operators.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -41,6 +41,7 @@
Finder->addMatcher(
cxxRecordDecl(
anyOf(has(cxxMethodDecl(isVirtual())), InheritsVirtualMethod),
+ unless(isFinal()),
unless(hasPublicVirtualOrProtectedNonVirtualDestructor()))
.bind("ProblematicClassOrStruct"),
this);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126891.438599.patch
Type: text/x-patch
Size: 2374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220621/aa15cd8c/attachment-0001.bin>
More information about the cfe-commits
mailing list