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 + ` 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 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; +}