Skip to content

[clang-tidy] Fix false positives in readability-redundant-inline-specifier #135391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
}

void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I wonder, maybe hasDeclContext should be used here instead of hasAncestor or just match cxxMethodDecl directly instead of functionDecl.

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);

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

if (getLangOpts().CPlusPlus17) {
const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
Finder->addMatcher(
varDecl(
isInlineSpecified(),
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,13 @@ class A
// CHECK-FIXES-STRICT: static float test4;
};
}

namespace ns {
class B
{
public:
~B();
};

inline B::~B() = default;
}
Loading