Skip to content

Commit 26e5d03

Browse files
bjosvrlavaee
authored andcommitted
[clang-tidy] Fix false positives in readability-redundant-inline-specifier (llvm#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 llvm#130745 --------- Signed-off-by: Björn Svensson <[email protected]>
1 parent bd092ac commit 26e5d03

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
7272
}
7373

7474
void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
75+
const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
7576
Finder->addMatcher(
7677
functionDecl(isInlineSpecified(),
77-
anyOf(isConstexpr(), isDeleted(), isDefaulted(),
78+
anyOf(isConstexpr(), isDeleted(),
79+
allOf(isDefaulted(), IsPartOfRecordDecl),
7880
isInternalLinkage(StrictMode),
79-
allOf(isDefinition(), hasAncestor(recordDecl()))))
81+
allOf(isDefinition(), IsPartOfRecordDecl)))
8082
.bind("fun_decl"),
8183
this);
8284

@@ -88,7 +90,6 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
8890
this);
8991

9092
if (getLangOpts().CPlusPlus17) {
91-
const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
9293
Finder->addMatcher(
9394
varDecl(
9495
isInlineSpecified(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ Changes in existing checks
313313
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
314314
`AllowedTypes`, that excludes specified types from adding qualifiers.
315315

316+
- Improved :doc:`readability-redundant-inline-specifier
317+
<clang-tidy/checks/readability/redundant-inline-specifier>` check by fixing
318+
false positives on out-of-line explicitly defaulted functions.
319+
316320
- Improved :doc:`readability-redundant-smartptr-get
317321
<clang-tidy/checks/readability/redundant-smartptr-get>` check by fixing
318322
some false positives involving smart pointers to arrays.

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,13 @@ class A
149149
// CHECK-FIXES-STRICT: static float test4;
150150
};
151151
}
152+
153+
namespace ns {
154+
class B
155+
{
156+
public:
157+
~B();
158+
};
159+
160+
inline B::~B() = default;
161+
}

0 commit comments

Comments
 (0)