[clang-tools-extra] 8351752 - [clang-tidy] Fix false positives in `readability-redundant-inline-specifier` (#135391)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 27 23:10:37 PDT 2025
Author: Björn Svensson
Date: 2025-06-28T09:10:34+03:00
New Revision: 8351752dbc405a44ebcb267f97c7f643e1a78544
URL: https://github.com/llvm/llvm-project/commit/8351752dbc405a44ebcb267f97c7f643e1a78544
DIFF: https://github.com/llvm/llvm-project/commit/8351752dbc405a44ebcb267f97c7f643e1a78544.diff
LOG: [clang-tidy] Fix false positives in `readability-redundant-inline-specifier` (#135391)
The out-of-line explicitly-defaulted definition is not the first
declaration, so it is not implicitly inline.
Alt. reference:
9.5.2 (3) Explicitly-defaulted functions in
[N4950](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf).
or https://timsong-cpp.github.io/cppwp/n4861/dcl.fct.def.default#3
Fixes #130745
---------
Signed-off-by: Björn Svensson <bjorn.a.svensson at est.tech>
Added:
Modified:
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 969bf2d1add6b..7f1882c775c59 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 934d52086b3b9..ccd6aa239c1cf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -313,6 +313,10 @@ 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-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.
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..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
@@ -149,3 +149,13 @@ class A
// CHECK-FIXES-STRICT: static float test4;
};
}
+
+namespace ns {
+class B
+{
+public:
+ ~B();
+};
+
+inline B::~B() = default;
+}
More information about the cfe-commits
mailing list