Skip to content

Commit 06676a7

Browse files
committed
fixup! [clang-tidy] Added check to detect redundant inline keyword
Removed unused part of matcher + clang-format
1 parent 3fadac1 commit 06676a7

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ using namespace clang::ast_matchers;
2424

2525
namespace clang::tidy::readability {
2626

27-
AST_POLYMORPHIC_MATCHER(isInlineSpecified, AST_POLYMORPHIC_SUPPORTED_TYPES(
28-
FunctionDecl,
29-
VarDecl)) {
27+
AST_POLYMORPHIC_MATCHER(isInlineSpecified,
28+
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
29+
VarDecl)) {
3030
if (const auto *FD = dyn_cast<FunctionDecl>(&Node))
3131
return FD->isInlineSpecified();
3232
if (const auto *VD = dyn_cast<VarDecl>(&Node))
3333
return VD->isInlineSpecified();
3434
llvm_unreachable("Not a valid polymorphic type");
3535
}
3636

37-
3837
static std::optional<SourceLocation>
3938
getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources,
4039
const LangOptions &LangOpts) {
4140
Token FirstToken;
4241
Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
43-
true);
42+
true);
4443
std::optional<Token> CurrentToken = FirstToken;
4544
while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() &&
4645
CurrentToken->isNot(tok::eof)) {
4746
if (CurrentToken->is(tok::raw_identifier) &&
4847
CurrentToken->getRawIdentifier() == "inline")
4948
return CurrentToken->getLocation();
5049

51-
CurrentToken = Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
50+
CurrentToken =
51+
Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
5252
}
5353
return std::nullopt;
5454
}
@@ -58,8 +58,7 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
5858
functionDecl(unless(isExpansionInSystemHeader()),
5959
unless(hasAncestor(lambdaExpr())), isInlineSpecified(),
6060
anyOf(isConstexpr(), isDeleted(),
61-
allOf(isDefinition(), hasAncestor(recordDecl()),
62-
unless(hasAncestor(cxxConstructorDecl())))))
61+
allOf(isDefinition(), hasAncestor(recordDecl()))))
6362
.bind("fun_decl"),
6463
this);
6564

@@ -71,16 +70,18 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
7170
this);
7271

7372
Finder->addMatcher(
74-
functionTemplateDecl(has(functionDecl(isInlineSpecified()))).bind("templ_decl"),
73+
functionTemplateDecl(has(functionDecl(isInlineSpecified())))
74+
.bind("templ_decl"),
7575
this);
7676
}
7777

7878
template <typename T>
7979
void RedundantInlineSpecifierCheck::handleMatchedDecl(
8080
const T *MatchedDecl, const SourceManager &Sources,
8181
const MatchFinder::MatchResult &Result, StringRef Message) {
82-
if (std::optional<SourceLocation> Loc = getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
83-
Result.Context->getLangOpts()))
82+
if (std::optional<SourceLocation> Loc =
83+
getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
84+
Result.Context->getLangOpts()))
8485
diag(*Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(*Loc);
8586
}
8687

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
namespace clang::tidy::readability {
1515

16-
/// Detects redundant ``inline`` specifiers on function and variable declarations.
16+
/// Detects redundant ``inline`` specifiers on function and variable
17+
/// declarations.
1718
///
1819
/// For the user-facing documentation see:
1920
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/readability-redundant-inline-specifier.html

0 commit comments

Comments
 (0)