53 const SourceManager &Sources,
54 const LangOptions &LangOpts) {
55 SourceLocation Loc = RangeLocation.getBegin();
60 Lexer::getRawToken(Loc, FirstToken, Sources, LangOpts,
true);
61 std::optional<Token> CurrentToken = FirstToken;
62 while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() &&
63 CurrentToken->isNot(tok::eof)) {
64 if (CurrentToken->is(tok::raw_identifier) &&
65 CurrentToken->getRawIdentifier() ==
"inline")
66 return CurrentToken->getLocation();
69 Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
75 const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
77 functionDecl(isInlineSpecified(),
78 anyOf(isConstexpr(), isDeleted(),
79 allOf(isDefaulted(), IsPartOfRecordDecl),
80 isInternalLinkage(StrictMode),
81 allOf(isDefinition(), IsPartOfRecordDecl)))
88 has(functionDecl(allOf(isInlineSpecified(), isDefinition()))))
92 if (getLangOpts().CPlusPlus17) {
96 anyOf(allOf(isInternalLinkage(StrictMode),
97 unless(allOf(hasInitializer(expr()), IsPartOfRecordDecl,
98 isStaticStorageClass()))),
99 allOf(isConstexpr(), IsPartOfRecordDecl)))
106void RedundantInlineSpecifierCheck::handleMatchedDecl(
107 const T *MatchedDecl,
const SourceManager &Sources,
108 const MatchFinder::MatchResult &Result, StringRef Message) {
110 MatchedDecl->getSourceRange(), Sources, Result.Context->getLangOpts());
112 diag(Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(Loc);
116 const MatchFinder::MatchResult &Result) {
117 const SourceManager &Sources = *Result.SourceManager;
119 if (
const auto *MatchedDecl =
120 Result.Nodes.getNodeAs<FunctionDecl>(
"fun_decl")) {
122 MatchedDecl, Sources, Result,
123 "function %0 has inline specifier but is implicitly inlined");
124 }
else if (
const auto *MatchedDecl =
125 Result.Nodes.getNodeAs<VarDecl>(
"var_decl")) {
127 MatchedDecl, Sources, Result,
128 "variable %0 has inline specifier but is implicitly inlined");
129 }
else if (
const auto *MatchedDecl =
130 Result.Nodes.getNodeAs<FunctionTemplateDecl>(
"templ_decl")) {
132 MatchedDecl, Sources, Result,
133 "function %0 has inline specifier but is implicitly inlined");
AST_POLYMORPHIC_MATCHER(isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc, NestedNameSpecifierLoc))
Matches AST nodes that were found within Abseil files.