Skip to content

Commit aa369fe

Browse files
committed
[clang-tidy] Fix false-positives in readability-redundant-inline-specifier
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 <[email protected]>
1 parent 08d6512 commit aa369fe

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
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
@@ -204,6 +204,10 @@ Changes in existing checks
204204
tolerating fix-it breaking compilation when functions is used as pointers
205205
to avoid matching usage of functions within the current compilation unit.
206206

207+
- Improved :doc:`readability-redundant-inline-specifier
208+
<clang-tidy/checks/readability/redundant-inline-specifier>` check by fixing
209+
false positives on out-of-line explicitly defaulted functions.
210+
207211
Removed checks
208212
^^^^^^^^^^^^^^
209213

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,4 @@ class B
158158
};
159159

160160
inline B::~B() = default;
161-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function '~B' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
162-
// CHECK-FIXES: B::~B() = default;
163161
}

0 commit comments

Comments
 (0)