[clang-tools-extra] [clang-tidy] Fix false positives in `readability-redundant-inline-specifier` (PR #135391)
Björn Svensson via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 24 02:06:26 PDT 2025
https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/135391
>From 08d6512c85ad2d4fa0372c73eeedc02012d88327 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= <bjorn.a.svensson at est.tech>
Date: Thu, 10 Apr 2025 13:46:28 +0200
Subject: [PATCH 1/3] [clang-tidy] Add additional test for
readability-redundant-inline-specifier
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Björn Svensson <bjorn.a.svensson at est.tech>
---
.../readability/redundant-inline-specifier.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index 14f9e88f7e721..4abf3a6a7917c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -149,3 +149,15 @@ class A
// CHECK-FIXES-STRICT: static float test4;
};
}
+
+namespace ns {
+class B
+{
+public:
+ ~B();
+};
+
+inline B::~B() = default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function '~B' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: B::~B() = default;
+}
>From aa369fe84b38640451ea49b3d673eaf8697496a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= <bjorn.a.svensson at est.tech>
Date: Fri, 11 Apr 2025 16:44:06 +0200
Subject: [PATCH 2/3] [clang-tidy] Fix false-positives in
readability-redundant-inline-specifier
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Only warn on explicitly defaulted functions which are inlined by default,
i.e. dont warn on out-of-line explicitly defaulted functions.
Signed-off-by: Björn Svensson <bjorn.a.svensson at est.tech>
---
.../readability/RedundantInlineSpecifierCheck.cpp | 7 ++++---
clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++
.../checkers/readability/redundant-inline-specifier.cpp | 2 --
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 1693e5c5e9cd4..33effb3dab977 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -72,11 +72,13 @@ static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
}
void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+ const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
Finder->addMatcher(
functionDecl(isInlineSpecified(),
- anyOf(isConstexpr(), isDeleted(), isDefaulted(),
+ anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefaulted(), IsPartOfRecordDecl),
isInternalLinkage(StrictMode),
- allOf(isDefinition(), hasAncestor(recordDecl()))))
+ allOf(isDefinition(), IsPartOfRecordDecl)))
.bind("fun_decl"),
this);
@@ -88,7 +90,6 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
this);
if (getLangOpts().CPlusPlus17) {
- const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
Finder->addMatcher(
varDecl(
isInlineSpecified(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..8fed96ceef647 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`readability-redundant-inline-specifier
+ <clang-tidy/checks/readability/redundant-inline-specifier>` check by fixing
+ false positives on out-of-line explicitly defaulted functions.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index 4abf3a6a7917c..882ce640b13c1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -158,6 +158,4 @@ class B
};
inline B::~B() = default;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function '~B' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
-// CHECK-FIXES: B::~B() = default;
}
>From 31b0bc08bc81f9efcb31e78f3b63d8422069da2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= <bjorn.a.svensson at est.tech>
Date: Tue, 24 Jun 2025 11:03:11 +0200
Subject: [PATCH 3/3] fixup: correcting order in ReleaseNote after merging main
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Björn Svensson <bjorn.a.svensson at est.tech>
---
clang-tools-extra/docs/ReleaseNotes.rst | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6eb61494861ba..0772150db8c89 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -308,14 +308,14 @@ Changes in existing checks
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
`AllowedTypes`, that excludes specified types from adding qualifiers.
-- Improved :doc:`readability-redundant-smartptr-get
- <clang-tidy/checks/readability/redundant-smartptr-get>` check by fixing
- some false positives involving smart pointers to arrays.
-
- Improved :doc:`readability-redundant-inline-specifier
<clang-tidy/checks/readability/redundant-inline-specifier>` check by fixing
false positives on out-of-line explicitly defaulted functions.
+- Improved :doc:`readability-redundant-smartptr-get
+ <clang-tidy/checks/readability/redundant-smartptr-get>` check by fixing
+ some false positives involving smart pointers to arrays.
+
Removed checks
^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list