[clang-tidy][NFC] Apply const-correctness to code (#203823)
This commit is contained in:
parent
6f916feb8b
commit
08940b5399
26 changed files with 78 additions and 69 deletions
|
|
@ -65,7 +65,7 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
|
|||
static ClangTidyOptions::OptionMap::const_iterator
|
||||
findPriorityOption(const ClangTidyOptions::OptionMap &Options,
|
||||
StringRef NamePrefix, StringRef LocalName,
|
||||
ClangTidyContext *Context) {
|
||||
const ClangTidyContext *Context) {
|
||||
llvm::StringSet<> *Collector = Context->getOptionsCollector();
|
||||
if (Collector) {
|
||||
Collector->insert((NamePrefix + LocalName).str());
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ static bool possibleVarDecl(const MacroInfo *MI, const Token *Tok) {
|
|||
isVarDeclKeyword(*Tok);
|
||||
}
|
||||
|
||||
static StringRef getMacroText(const MacroInfo *MI, Preprocessor *PP) {
|
||||
static StringRef getMacroText(const MacroInfo *MI, const Preprocessor *PP) {
|
||||
if (MI->tokens_empty())
|
||||
return {};
|
||||
return Lexer::getSourceText(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ AST_MATCHER(DeclRefExpr, refersToEnclosingVariableOrCapture) {
|
|||
static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
|
||||
const ParmVarDecl *ParmVar,
|
||||
const TemplateTypeParmDecl *TypeParmDecl,
|
||||
DiagnosticBuilder &Diag,
|
||||
const DiagnosticBuilder &Diag,
|
||||
const ASTContext &Context) {
|
||||
const SourceManager &SM = Context.getSourceManager();
|
||||
const LangOptions &LangOpts = Context.getLangOpts();
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ isFixedGivenLengthAndUnknownSrc(const MatchFinder::MatchResult &Result) {
|
|||
static void lengthExprHandle(const Expr *LengthExpr,
|
||||
LengthHandleKind LengthHandle,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
LengthExpr = LengthExpr->IgnoreParenImpCasts();
|
||||
|
||||
// See whether we work with a macro.
|
||||
|
|
@ -360,14 +360,14 @@ static void lengthExprHandle(const Expr *LengthExpr,
|
|||
|
||||
static void lengthArgHandle(LengthHandleKind LengthHandle,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *LengthExpr = Result.Nodes.getNodeAs<Expr>(LengthExprName);
|
||||
lengthExprHandle(LengthExpr, LengthHandle, Result, Diag);
|
||||
}
|
||||
|
||||
static void lengthArgPosHandle(unsigned ArgPos, LengthHandleKind LengthHandle,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
|
||||
lengthExprHandle(FunctionExpr->getArg(ArgPos), LengthHandle, Result, Diag);
|
||||
}
|
||||
|
|
@ -375,7 +375,7 @@ static void lengthArgPosHandle(unsigned ArgPos, LengthHandleKind LengthHandle,
|
|||
// The string handler functions are only operates with plain 'char'/'wchar_t'
|
||||
// without 'unsigned/signed', therefore we need to cast it.
|
||||
static bool isDestExprFix(const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *Dest = Result.Nodes.getNodeAs<Expr>(DestExprName);
|
||||
if (!Dest)
|
||||
return false;
|
||||
|
|
@ -392,7 +392,7 @@ static bool isDestExprFix(const MatchFinder::MatchResult &Result,
|
|||
// If the destination array is the same length as the given length we have to
|
||||
// increase the capacity by one to create space for the null terminator.
|
||||
static bool isDestCapacityFix(const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const bool IsOverflows = isDestCapacityOverflows(Result);
|
||||
if (IsOverflows)
|
||||
if (const Expr *CapacityExpr = getDestCapacityExpr(Result))
|
||||
|
|
@ -402,7 +402,7 @@ static bool isDestCapacityFix(const MatchFinder::MatchResult &Result,
|
|||
}
|
||||
|
||||
static void removeArg(int ArgPos, const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
// This is the following structure: (src, '\0', strlen(src))
|
||||
// ArgToRemove: ~~~~~~~~~~~
|
||||
// LHSArg: ~~~~
|
||||
|
|
@ -418,7 +418,7 @@ static void removeArg(int ArgPos, const MatchFinder::MatchResult &Result,
|
|||
|
||||
static void renameFunc(StringRef NewFuncName,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
|
||||
const int FuncNameLength =
|
||||
FunctionExpr->getDirectCallee()->getIdentifier()->getLength();
|
||||
|
|
@ -433,7 +433,7 @@ static void renameFunc(StringRef NewFuncName,
|
|||
|
||||
static void renameMemcpy(StringRef Name, bool IsCopy, bool IsSafe,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
SmallString<10> NewFuncName;
|
||||
NewFuncName = (Name[0] != 'w') ? "str" : "wcs";
|
||||
NewFuncName += IsCopy ? "cpy" : "ncpy";
|
||||
|
|
@ -443,7 +443,7 @@ static void renameMemcpy(StringRef Name, bool IsCopy, bool IsSafe,
|
|||
|
||||
static void insertDestCapacityArg(bool IsOverflows, StringRef Name,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
|
||||
SmallString<64> NewSecondArg;
|
||||
|
||||
|
|
@ -464,7 +464,7 @@ static void insertDestCapacityArg(bool IsOverflows, StringRef Name,
|
|||
|
||||
static void insertNullTerminatorExpr(StringRef Name,
|
||||
const MatchFinder::MatchResult &Result,
|
||||
DiagnosticBuilder &Diag) {
|
||||
const DiagnosticBuilder &Diag) {
|
||||
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
|
||||
const int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber(
|
||||
FunctionExpr->getBeginLoc());
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ static std::string getNameAsString(const NamedDecl *Decl) {
|
|||
|
||||
// Returns E as written in the source code. Used to handle 'using' and
|
||||
// 'typedef'ed names of grand-parent classes.
|
||||
static std::string getExprAsString(const Expr &E, ASTContext &AC) {
|
||||
static std::string getExprAsString(const Expr &E, const ASTContext &AC) {
|
||||
std::string Text = tooling::fixit::getText(E, AC).str();
|
||||
llvm::erase_if(Text, [](char C) {
|
||||
return llvm::isSpace(static_cast<unsigned char>(C));
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ static MoveType determineMoveType(const FunctionDecl *FuncDecl) {
|
|||
|
||||
static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
|
||||
const UseAfterMove &Use, ClangTidyCheck *Check,
|
||||
ASTContext *Context, MoveType Type,
|
||||
const ASTContext *Context, MoveType Type,
|
||||
const FunctionDecl *MoveDecl) {
|
||||
const SourceLocation UseLoc = Use.DeclRef->getExprLoc();
|
||||
const SourceLocation MoveLoc = MovingCall->getExprLoc();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
|
|||
FuncDecl->getDescribedTemplateParams();
|
||||
|
||||
if (!ReturnList) {
|
||||
ArrayRef<TemplateParameterList *> TPLs =
|
||||
const ArrayRef<TemplateParameterList *> TPLs =
|
||||
FuncDecl->getTemplateParameterLists();
|
||||
|
||||
if (!TPLs.empty())
|
||||
|
|
|
|||
|
|
@ -171,9 +171,10 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
|
|||
}
|
||||
}
|
||||
|
||||
static void addConstFixits(DiagnosticBuilder &Diag, const VarDecl *Variable,
|
||||
const FunctionDecl *Function, ASTContext &Context,
|
||||
Qualifiers::TQ Qualifier,
|
||||
static void addConstFixits(const DiagnosticBuilder &Diag,
|
||||
const VarDecl *Variable,
|
||||
const FunctionDecl *Function,
|
||||
const ASTContext &Context, Qualifiers::TQ Qualifier,
|
||||
utils::fixit::QualifierTarget Target,
|
||||
utils::fixit::QualifierPolicy Policy) {
|
||||
// If this is a parameter, also add fixits for corresponding parameters in
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ void MisplacedConstCheck::registerMatchers(MatchFinder *Finder) {
|
|||
this);
|
||||
}
|
||||
|
||||
static QualType guessAlternateQualification(ASTContext &Context, QualType QT) {
|
||||
static QualType guessAlternateQualification(const ASTContext &Context,
|
||||
QualType QT) {
|
||||
// We're given a QualType from a typedef where the qualifiers apply to the
|
||||
// pointer instead of the pointee. Strip the const qualifier from the pointer
|
||||
// type and add it to the pointee instead.
|
||||
|
|
@ -47,7 +48,7 @@ static QualType guessAlternateQualification(ASTContext &Context, QualType QT) {
|
|||
|
||||
void MisplacedConstCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
const auto *Var = Result.Nodes.getNodeAs<ValueDecl>("decl");
|
||||
ASTContext &Ctx = *Result.Context;
|
||||
const ASTContext &Ctx = *Result.Context;
|
||||
const QualType CanQT = Var->getType().getCanonicalType();
|
||||
|
||||
SourceLocation AliasLoc;
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ static CallStackTy pathfindSomeCycle(ArrayRef<CallGraphNode *> SCC) {
|
|||
CallStackSet;
|
||||
|
||||
// Arbitrarily take the first element of SCC as entry point.
|
||||
CallGraphNode::CallRecord EntryNode(SCC.front(), /*CallExpr=*/nullptr);
|
||||
const CallGraphNode::CallRecord EntryNode(SCC.front(), /*CallExpr=*/nullptr);
|
||||
// Continue recursing into subsequent callees that are part of this SCC,
|
||||
// and are thus known to be part of the call graph loop, until loop forms.
|
||||
CallGraphNode::CallRecord *Node = &EntryNode;
|
||||
const CallGraphNode::CallRecord *Node = &EntryNode;
|
||||
while (true) {
|
||||
// Did we see this node before?
|
||||
if (!CallStackSet.insert(*Node))
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ struct OptionEnumMapping<misc::UseInternalLinkageCheck::FixModeKind> {
|
|||
|
||||
namespace clang::tidy::misc {
|
||||
|
||||
static bool isInMainFile(SourceLocation L, SourceManager &SM,
|
||||
static bool isInMainFile(SourceLocation L, const SourceManager &SM,
|
||||
const FileExtensionsSet &HeaderFileExtensions) {
|
||||
for (;;) {
|
||||
if (utils::isExpansionLocInHeaderFile(L, SM, HeaderFileExtensions))
|
||||
|
|
|
|||
|
|
@ -432,8 +432,8 @@ getContainerFromBeginEndCall(const Expr *Init, bool IsBegin, bool *IsArrow,
|
|||
///
|
||||
/// BeginExpr must be a member call to a function named "begin()", and EndExpr
|
||||
/// must be a member.
|
||||
static const Expr *findContainer(ASTContext *Context, const Expr *BeginExpr,
|
||||
const Expr *EndExpr,
|
||||
static const Expr *findContainer(const ASTContext *Context,
|
||||
const Expr *BeginExpr, const Expr *EndExpr,
|
||||
bool *ContainerNeedsDereference,
|
||||
bool IsReverse) {
|
||||
// Now that we know the loop variable and test expression, make sure they are
|
||||
|
|
@ -461,7 +461,7 @@ static const Expr *findContainer(ASTContext *Context, const Expr *BeginExpr,
|
|||
}
|
||||
|
||||
/// Obtain the original source code text from a SourceRange.
|
||||
static StringRef getStringFromRange(SourceManager &SourceMgr,
|
||||
static StringRef getStringFromRange(const SourceManager &SourceMgr,
|
||||
const LangOptions &LangOpts,
|
||||
SourceRange Range) {
|
||||
if (SourceMgr.getFileID(Range.getBegin()) !=
|
||||
|
|
|
|||
|
|
@ -186,7 +186,8 @@ const Expr *digThroughConstructorsConversions(const Expr *E) {
|
|||
}
|
||||
|
||||
/// Returns true when two Exprs are equivalent.
|
||||
bool areSameExpr(ASTContext *Context, const Expr *First, const Expr *Second) {
|
||||
bool areSameExpr(const ASTContext *Context, const Expr *First,
|
||||
const Expr *Second) {
|
||||
return utils::areStatementsIdentical(First, Second, *Context, true);
|
||||
}
|
||||
|
||||
|
|
@ -277,7 +278,8 @@ static bool isIndexInSubscriptExpr(const Expr *IndexExpr,
|
|||
/// (*container)[index]
|
||||
/// (*container).at(index)
|
||||
/// \endcode
|
||||
static bool isIndexInSubscriptExpr(ASTContext *Context, const Expr *IndexExpr,
|
||||
static bool isIndexInSubscriptExpr(const ASTContext *Context,
|
||||
const Expr *IndexExpr,
|
||||
const VarDecl *IndexVar, const Expr *Obj,
|
||||
const Expr *SourceExpr, bool PermitDeref) {
|
||||
if (!SourceExpr || !Obj || !isIndexInSubscriptExpr(IndexExpr, IndexVar))
|
||||
|
|
@ -339,7 +341,7 @@ static bool isDereferenceOfUop(const UnaryOperator *Uop,
|
|||
/// // use t, do not use i
|
||||
/// }
|
||||
/// \endcode
|
||||
static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
|
||||
static bool isAliasDecl(const ASTContext *Context, const Decl *TheDecl,
|
||||
const VarDecl *IndexVar) {
|
||||
const auto *VDecl = dyn_cast<VarDecl>(TheDecl);
|
||||
if (!VDecl)
|
||||
|
|
@ -422,7 +424,7 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
|
|||
/// for (int i = 0; i < N; ++i) { /* use arr[i] */ }
|
||||
/// for (int i = 0; i < arraysize(arr); ++i) { /* use arr[i] */ }
|
||||
/// \endcode
|
||||
static bool arrayMatchesBoundExpr(ASTContext *Context,
|
||||
static bool arrayMatchesBoundExpr(const ASTContext *Context,
|
||||
const QualType &ArrayType,
|
||||
const Expr *ConditionExpr) {
|
||||
if (!ConditionExpr || ConditionExpr->isValueDependent())
|
||||
|
|
|
|||
|
|
@ -268,7 +268,8 @@ using UsageResult = SmallVector<Usage, 8>;
|
|||
|
||||
// General functions used by ForLoopIndexUseVisitor and LoopConvertCheck.
|
||||
const Expr *digThroughConstructorsConversions(const Expr *E);
|
||||
bool areSameExpr(ASTContext *Context, const Expr *First, const Expr *Second);
|
||||
bool areSameExpr(const ASTContext *Context, const Expr *First,
|
||||
const Expr *Second);
|
||||
const DeclRefExpr *getDeclRef(const Expr *E);
|
||||
bool areSameVariable(const ValueDecl *First, const ValueDecl *Second);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
|
|||
/// Replaces the provided range with the text "nullptr", but only if
|
||||
/// the start and end location are both in main file.
|
||||
/// Returns true if and only if a replacement was made.
|
||||
static void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
|
||||
static void replaceWithNullptr(ClangTidyCheck &Check, const SourceManager &SM,
|
||||
SourceLocation StartLoc, SourceLocation EndLoc) {
|
||||
const CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
|
||||
// Add a space if nullptr follows an alphanumeric character. This happens
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ static auto getStringTypeMatcher(StringRef CharType) {
|
|||
return hasCanonicalType(hasDeclaration(cxxRecordDecl(hasName(CharType))));
|
||||
}
|
||||
|
||||
static void fixReturns(const FunctionDecl *FuncDecl, DiagnosticBuilder &Diag,
|
||||
ASTContext &Context) {
|
||||
static void fixReturns(const FunctionDecl *FuncDecl,
|
||||
const DiagnosticBuilder &Diag, ASTContext &Context) {
|
||||
auto Matches = match(
|
||||
findAll(returnStmt(hasReturnValue(ignoringParenImpCasts(
|
||||
cxxTemporaryObjectExpr(argumentCountIs(0)).bind("temp_obj_expr"))))),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ using namespace clang::ast_matchers;
|
|||
|
||||
namespace clang::tidy::performance {
|
||||
|
||||
static void replaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag,
|
||||
static void replaceCallWithArg(const CallExpr *Call,
|
||||
const DiagnosticBuilder &Diag,
|
||||
const SourceManager &SM,
|
||||
const LangOptions &LangOpts) {
|
||||
const Expr *Arg = Call->getArg(0);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ static constexpr StringRef FunctionDeclId = "functionDecl";
|
|||
static constexpr StringRef OldVarDeclId = "oldVarDecl";
|
||||
|
||||
static void recordFixes(const VarDecl &Var, ASTContext &Context,
|
||||
DiagnosticBuilder &Diagnostic) {
|
||||
const DiagnosticBuilder &Diagnostic) {
|
||||
Diagnostic << utils::fixit::changeVarDeclToReference(Var, Context);
|
||||
if (!Var.getType().isLocalConstQualified()) {
|
||||
if (std::optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
|
||||
|
|
@ -38,8 +38,8 @@ static void recordFixes(const VarDecl &Var, ASTContext &Context,
|
|||
}
|
||||
}
|
||||
|
||||
static std::optional<SourceLocation> firstLocAfterNewLine(SourceLocation Loc,
|
||||
SourceManager &SM) {
|
||||
static std::optional<SourceLocation>
|
||||
firstLocAfterNewLine(SourceLocation Loc, const SourceManager &SM) {
|
||||
bool Invalid = false;
|
||||
const char *TextAfter = SM.getCharacterData(Loc, &Invalid);
|
||||
if (Invalid)
|
||||
|
|
@ -49,7 +49,7 @@ static std::optional<SourceLocation> firstLocAfterNewLine(SourceLocation Loc,
|
|||
}
|
||||
|
||||
static void recordRemoval(const DeclStmt &Stmt, ASTContext &Context,
|
||||
DiagnosticBuilder &Diagnostic) {
|
||||
const DiagnosticBuilder &Diagnostic) {
|
||||
auto &SM = Context.getSourceManager();
|
||||
// Attempt to remove trailing comments as well.
|
||||
auto Tok = utils::lexer::findNextTokenSkippingComments(Stmt.getEndLoc(), SM,
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ void ConvertMemberFunctionsToStaticCheck::registerMatchers(
|
|||
}
|
||||
|
||||
/// Obtain the original source code text from a SourceRange.
|
||||
static StringRef getStringFromRange(SourceManager &SourceMgr,
|
||||
static StringRef getStringFromRange(const SourceManager &SourceMgr,
|
||||
const LangOptions &LangOpts,
|
||||
SourceRange Range) {
|
||||
if (SourceMgr.getFileID(Range.getBegin()) !=
|
||||
|
|
@ -145,7 +145,7 @@ static StringRef getStringFromRange(SourceManager &SourceMgr,
|
|||
}
|
||||
|
||||
static SourceRange getLocationOfConst(const TypeSourceInfo *TSI,
|
||||
SourceManager &SourceMgr,
|
||||
const SourceManager &SourceMgr,
|
||||
const LangOptions &LangOpts) {
|
||||
assert(TSI);
|
||||
const auto FTL = TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>();
|
||||
|
|
|
|||
|
|
@ -124,8 +124,9 @@ static bool containsDeclInScope(const Stmt *Node) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static void removeElseAndBrackets(DiagnosticBuilder &Diag, ASTContext &Context,
|
||||
const Stmt *Else, SourceLocation ElseLoc) {
|
||||
static void removeElseAndBrackets(const DiagnosticBuilder &Diag,
|
||||
ASTContext &Context, const Stmt *Else,
|
||||
SourceLocation ElseLoc) {
|
||||
auto Remap = [&](SourceLocation Loc) {
|
||||
return Context.getSourceManager().getExpansionLoc(Loc);
|
||||
};
|
||||
|
|
@ -257,9 +258,9 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
if (IsLastInScope) {
|
||||
// If the if statement is the last statement of its enclosing statements
|
||||
// scope, we can pull the decl out of the if statement.
|
||||
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter
|
||||
<< SourceRange(ElseLoc);
|
||||
const DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter
|
||||
<< SourceRange(ElseLoc);
|
||||
if (checkInitDeclUsageInElse(If) != nullptr) {
|
||||
Diag << tooling::fixit::createReplacement(
|
||||
SourceRange(If->getIfLoc()),
|
||||
|
|
@ -293,9 +294,9 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
if (IsLastInScope) {
|
||||
// If the if statement is the last statement of its enclosing statements
|
||||
// scope, we can pull the decl out of the if statement.
|
||||
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter
|
||||
<< SourceRange(ElseLoc);
|
||||
const DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter
|
||||
<< SourceRange(ElseLoc);
|
||||
Diag << tooling::fixit::createReplacement(
|
||||
SourceRange(If->getIfLoc()),
|
||||
(tooling::fixit::getText(*If->getInit(), *Result.Context) +
|
||||
|
|
@ -311,8 +312,9 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
return;
|
||||
}
|
||||
|
||||
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter << SourceRange(ElseLoc);
|
||||
const DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
|
||||
<< ControlFlowInterrupter
|
||||
<< SourceRange(ElseLoc);
|
||||
removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ static bool isInitializedByLiteral(const EnumConstantDecl *Enumerator) {
|
|||
return Init->isIntegerConstantExpr(Enumerator->getASTContext());
|
||||
}
|
||||
|
||||
static void cleanInitialValue(DiagnosticBuilder &Diag,
|
||||
static void cleanInitialValue(const DiagnosticBuilder &Diag,
|
||||
const EnumConstantDecl *ECD,
|
||||
const SourceManager &SM,
|
||||
const LangOptions &LangOpts) {
|
||||
|
|
@ -203,14 +203,15 @@ void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
const SourceLocation Loc = ECD->getLocation();
|
||||
if (Loc.isInvalid() || Loc.isMacroID())
|
||||
return;
|
||||
DiagnosticBuilder Diag = diag(Loc, "zero initial value for the first "
|
||||
"enumerator in '%0' can be disregarded")
|
||||
<< getName(Enum);
|
||||
const DiagnosticBuilder Diag =
|
||||
diag(Loc, "zero initial value for the first "
|
||||
"enumerator in '%0' can be disregarded")
|
||||
<< getName(Enum);
|
||||
cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
|
||||
return;
|
||||
}
|
||||
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("sequential")) {
|
||||
DiagnosticBuilder Diag =
|
||||
const DiagnosticBuilder Diag =
|
||||
diag(Enum->getBeginLoc(),
|
||||
"sequential initial value in '%0' can be ignored")
|
||||
<< getName(Enum);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ AST_MATCHER(Stmt, isNULLMacroExpansion) {
|
|||
|
||||
static StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind,
|
||||
QualType Type,
|
||||
ASTContext &Context) {
|
||||
const ASTContext &Context) {
|
||||
switch (CastExprKind) {
|
||||
case CK_IntegralToBoolean:
|
||||
return Type->isUnsignedIntegerType() ? "0u" : "0";
|
||||
|
|
@ -71,7 +71,7 @@ static bool isUnaryLogicalNotOperator(const Stmt *Statement) {
|
|||
return UnaryOperatorExpr && UnaryOperatorExpr->getOpcode() == UO_LNot;
|
||||
}
|
||||
|
||||
static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
|
||||
static void fixGenericExprCastToBool(const DiagnosticBuilder &Diag,
|
||||
const ImplicitCastExpr *Cast,
|
||||
const Stmt *Parent, ASTContext &Context,
|
||||
bool UseUpperCaseLiteralSuffix) {
|
||||
|
|
@ -167,7 +167,7 @@ static bool needsSpacePrefix(SourceLocation Loc, ASTContext &Context) {
|
|||
return !AllowedCharacters.contains(SpaceBeforeStmtStr.back());
|
||||
}
|
||||
|
||||
static void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
|
||||
static void fixGenericExprCastFromBool(const DiagnosticBuilder &Diag,
|
||||
const ImplicitCastExpr *Cast,
|
||||
ASTContext &Context,
|
||||
StringRef OtherType) {
|
||||
|
|
@ -197,7 +197,7 @@ static void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
|
|||
|
||||
static StringRef
|
||||
getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral,
|
||||
QualType DestType, ASTContext &Context) {
|
||||
QualType DestType, const ASTContext &Context) {
|
||||
// Prior to C++11, false literal could be implicitly converted to pointer.
|
||||
if (!Context.getLangOpts().CPlusPlus11 &&
|
||||
(DestType->isPointerType() || DestType->isMemberPointerType()) &&
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
|||
return isFileExtension(SM.getFilename(ExpansionLoc), HeaderFileExtensions);
|
||||
}
|
||||
|
||||
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
|
||||
bool isPresumedLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
||||
const FileExtensionsSet &HeaderFileExtensions) {
|
||||
const PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
|
||||
return isFileExtension(PresumedLocation.getFilename(), HeaderFileExtensions);
|
||||
}
|
||||
|
||||
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
|
||||
bool isSpellingLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
||||
const FileExtensionsSet &HeaderFileExtensions) {
|
||||
const SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
|
||||
return isFileExtension(SM.getFilename(SpellingLoc), HeaderFileExtensions);
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
|||
const FileExtensionsSet &HeaderFileExtensions);
|
||||
|
||||
/// Checks whether presumed location of \p Loc is in header file.
|
||||
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
|
||||
bool isPresumedLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
||||
const FileExtensionsSet &HeaderFileExtensions);
|
||||
|
||||
/// Checks whether spelling location of \p Loc is in header file.
|
||||
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
|
||||
bool isSpellingLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
|
||||
const FileExtensionsSet &HeaderFileExtensions);
|
||||
|
||||
/// Returns recommended default value for the list of header file
|
||||
|
|
|
|||
|
|
@ -734,7 +734,7 @@ void FormatStringConverter::appendFormatText(const StringRef Text) {
|
|||
}
|
||||
|
||||
static std::string withoutCStrReplacement(const BoundNodes &CStrRemovalMatch,
|
||||
ASTContext &Context) {
|
||||
const ASTContext &Context) {
|
||||
const auto *Arg = CStrRemovalMatch.getNodeAs<Expr>("arg");
|
||||
const auto *Member = CStrRemovalMatch.getNodeAs<MemberExpr>("member");
|
||||
const bool Arrow = Member->isArrow();
|
||||
|
|
|
|||
|
|
@ -160,8 +160,8 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) {
|
|||
}
|
||||
}
|
||||
|
||||
static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
|
||||
ArrayRef<unsigned> Indexes,
|
||||
static void removeFunctionArgs(const DiagnosticBuilder &Diag,
|
||||
const CallExpr &Call, ArrayRef<unsigned> Indexes,
|
||||
const ASTContext &Ctx) {
|
||||
SmallVector<unsigned> Sorted(Indexes);
|
||||
llvm::sort(Sorted);
|
||||
|
|
@ -211,7 +211,7 @@ static bool isResultUsed(const CallExpr &Call,
|
|||
return isResultUsed(DynTypedNode::create(Call), Result);
|
||||
}
|
||||
|
||||
static void insertAccessor(DiagnosticBuilder &Diag, const CallExpr &Call,
|
||||
static void insertAccessor(const DiagnosticBuilder &Diag, const CallExpr &Call,
|
||||
StringRef Accessor, const ASTContext &Ctx) {
|
||||
const SourceLocation End = Lexer::getLocForEndOfToken(
|
||||
Call.getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts());
|
||||
|
|
|
|||
Loading…
Reference in a new issue