52 const SourceManager &Sources,
53 const LangOptions &LangOpts) {
54 const SourceLocation Loc = RangeLocation.getBegin();
59 Lexer::getRawToken(Loc, FirstToken, Sources, LangOpts,
true);
60 std::optional<Token> CurrentToken = FirstToken;
61 while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() &&
62 CurrentToken->isNot(tok::eof)) {
63 if (CurrentToken->is(tok::raw_identifier) &&
64 CurrentToken->getRawIdentifier() ==
"inline")
65 return CurrentToken->getLocation();
68 Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
74 const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
76 functionDecl(isInlineSpecified(),
77 anyOf(isConstexpr(), isDeleted(),
78 allOf(isDefaulted(), IsPartOfRecordDecl),
79 isInternalLinkage(StrictMode),
80 allOf(isDefinition(), IsPartOfRecordDecl)))
87 has(functionDecl(allOf(isInlineSpecified(), isDefinition()))))
91 if (getLangOpts().CPlusPlus17) {
95 anyOf(allOf(isInternalLinkage(StrictMode),
96 unless(allOf(hasInitializer(expr()), IsPartOfRecordDecl,
97 isStaticStorageClass()))),
98 allOf(isConstexpr(), IsPartOfRecordDecl)))
105void RedundantInlineSpecifierCheck::handleMatchedDecl(
106 const T *MatchedDecl,
const SourceManager &Sources,
107 const MatchFinder::MatchResult &Result, StringRef Message) {
109 MatchedDecl->getSourceRange(), Sources, Result.Context->getLangOpts());
111 diag(Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(Loc);
115 const MatchFinder::MatchResult &Result) {
116 const SourceManager &Sources = *Result.SourceManager;
118 if (
const auto *MatchedDecl =
119 Result.Nodes.getNodeAs<FunctionDecl>(
"fun_decl")) {
121 MatchedDecl, Sources, Result,
122 "function %0 has inline specifier but is implicitly inlined");
123 }
else if (
const auto *MatchedDecl =
124 Result.Nodes.getNodeAs<VarDecl>(
"var_decl")) {
126 MatchedDecl, Sources, Result,
127 "variable %0 has inline specifier but is implicitly inlined");
128 }
else if (
const auto *MatchedDecl =
129 Result.Nodes.getNodeAs<FunctionTemplateDecl>(
"templ_decl")) {
131 MatchedDecl, Sources, Result,
132 "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.