Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}

void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
std::string BadDecl = "badDecl";
const std::string BadDecl = "badDecl";
Finder->addMatcher(
varDecl(unless(hasInitializer(anything())), unless(isInstantiated()),
isLocalVarDecl(), unless(isStaticLocal()), isDefinition(),
Expand Down Expand Up @@ -82,7 +82,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
if (MatchedDecl->getEndLoc().isMacroID())
return;

QualType TypePtr = MatchedDecl->getType();
const QualType TypePtr = MatchedDecl->getType();
std::optional<const char *> InitializationString;
bool AddMathInclude = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MacroUsageCallbacks : public PPCallbacks {
SM.isWrittenInCommandLineFile(MD->getLocation()))
return;

StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
const StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM")
return;
if (!CheckCapsOnly && !RegExp.match(MacroName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ void MisleadingCaptureDefaultByValueCheck::check(
return;

if (Lambda->getCaptureDefault() == LCD_ByCopy) {
bool IsThisImplicitlyCaptured = std::any_of(
const bool IsThisImplicitlyCaptured = std::any_of(
Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
[](const LambdaCapture &Capture) { return Capture.capturesThis(); });
auto Diag = diag(Lambda->getCaptureDefaultLoc(),
"lambdas that %select{|implicitly }0capture 'this' "
"should not specify a by-value capture default")
<< IsThisImplicitlyCaptured;

std::string ReplacementText = createReplacementText(Lambda);
SourceLocation DefaultCaptureEnd =
const std::string ReplacementText = createReplacementText(Lambda);
const SourceLocation DefaultCaptureEnd =
findDefaultCaptureEnd(Lambda, *Result.Context);
Diag << FixItHint::CreateReplacement(
CharSourceRange::getCharRange(Lambda->getCaptureDefaultLoc(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ AST_MATCHER_P(QualType, possiblyPackExpansionOf,
}

AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
ast_matchers::internal::Matcher<QualType> Inner = possiblyPackExpansionOf(
qualType(rValueReferenceType(),
references(templateTypeParmType(
hasDeclaration(templateTypeParmDecl()))),
unless(references(qualType(isConstQualified())))));
const ast_matchers::internal::Matcher<QualType> Inner =
possiblyPackExpansionOf(
qualType(rValueReferenceType(),
references(templateTypeParmType(
hasDeclaration(templateTypeParmDecl()))),
unless(references(qualType(isConstQualified())))));
if (!Inner.matches(Node.getType(), Finder, Builder))
return false;

Expand All @@ -43,7 +44,7 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
if (!FuncTemplate)
return false;

QualType ParamType =
const QualType ParamType =
Node.getType().getNonPackExpansionType()->getPointeeType();
const auto *TemplateType = ParamType->getAsCanonical<TemplateTypeParmType>();
if (!TemplateType)
Expand All @@ -54,10 +55,10 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
}

AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
IdentifierInfo *II = Node.getIdentifier();
const IdentifierInfo *II = Node.getIdentifier();
if (nullptr == II)
return false;
StringRef Name = II->getName();
const StringRef Name = II->getName();

return Builder->removeBindings(
[this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void NoSuspendWithLockCheck::registerMatchers(MatchFinder *Finder) {
hasDeclaration(namedDecl(matchers::matchesAnyListedName(
utils::options::parseStringList(LockGuards)))));

StatementMatcher Lock =
const StatementMatcher Lock =
declStmt(has(varDecl(hasType(LockType)).bind("lock-decl")))
.bind("lock-decl-stmt");
Finder->addMatcher(
Expand Down Expand Up @@ -55,12 +55,12 @@ void NoSuspendWithLockCheck::check(const MatchFinder::MatchResult &Result) {
Options.AddImplicitDtors = true;
Options.AddTemporaryDtors = true;

std::unique_ptr<CFG> TheCFG = CFG::buildCFG(
const std::unique_ptr<CFG> TheCFG = CFG::buildCFG(
nullptr, const_cast<clang::CompoundStmt *>(Block), &Context, Options);
if (!TheCFG)
return;

utils::ExprSequence Sequence(TheCFG.get(), Block, &Context);
const utils::ExprSequence Sequence(TheCFG.get(), Block, &Context);
const Stmt *LastBlockStmt = Block->body_back();
if (Sequence.inSequence(LockStmt, Suspend) &&
(Suspend == LastBlockStmt ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ void PreferMemberInitializerCheck::check(
llvm::DenseMap<const FieldDecl *, AssignedLevel> AssignedFields{};

for (const CXXCtorInitializer *Init : Ctor->inits())
if (FieldDecl *Field = Init->getMember())
if (const FieldDecl *Field = Init->getMember())
updateAssignmentLevel(Field, Init->getInit(), Ctor, AssignedFields);

for (const Stmt *S : Body->body()) {
if (S->getBeginLoc().isMacroID()) {
StringRef MacroName = Lexer::getImmediateMacroName(
const StringRef MacroName = Lexer::getImmediateMacroName(
S->getBeginLoc(), *Result.SourceManager, getLangOpts());
if (MacroName.contains_insensitive("assert"))
return;
Expand Down Expand Up @@ -206,7 +206,7 @@ void PreferMemberInitializerCheck::check(
bool AddComma = false;
bool AddBrace = false;
bool InvalidFix = false;
unsigned Index = Field->getFieldIndex();
const unsigned Index = Field->getFieldIndex();
const CXXCtorInitializer *LastInListInit = nullptr;
for (const CXXCtorInitializer *Init : Ctor->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
Expand Down Expand Up @@ -276,7 +276,7 @@ void PreferMemberInitializerCheck::check(
<< Field;
if (InvalidFix)
continue;
StringRef NewInit = Lexer::getSourceText(
const StringRef NewInit = Lexer::getSourceText(
Result.SourceManager->getExpansionRange(InitValue->getSourceRange()),
*Result.SourceManager, getLangOpts());
if (HasInitAlready) {
Expand All @@ -288,8 +288,8 @@ void PreferMemberInitializerCheck::check(
else
Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
} else {
SmallString<128> Insertion({InsertPrefix, Field->getName(), "(", NewInit,
AddComma ? "), " : ")"});
const SmallString<128> Insertion({InsertPrefix, Field->getName(), "(",
NewInit, AddComma ? "), " : ")"});
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
FirstToCtorInits);
FirstToCtorInits = areDiagsSelfContained();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ AST_MATCHER_P(Expr, hasParentIgnoringImpCasts,
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
const Expr *E = &Node;
do {
DynTypedNodeList Parents = Finder->getASTContext().getParents(*E);
const DynTypedNodeList Parents = Finder->getASTContext().getParents(*E);
if (Parents.size() != 1)
return false;
E = Parents[0].get<Expr>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void ProBoundsConstantArrayIndexCheck::check(
else
BaseRange =
cast<CXXOperatorCallExpr>(Matched)->getArg(0)->getSourceRange();
SourceRange IndexRange = IndexExpr->getSourceRange();
const SourceRange IndexRange = IndexExpr->getSourceRange();

auto Diag = diag(Matched->getExprLoc(),
"do not use array subscript when the index is "
Expand Down Expand Up @@ -115,7 +115,7 @@ void ProBoundsConstantArrayIndexCheck::check(
const auto &SizeArg = TemplateArgs[1];
if (SizeArg.getKind() != TemplateArgument::Integral)
return;
llvm::APInt ArraySize = SizeArg.getAsIntegral();
const llvm::APInt ArraySize = SizeArg.getAsIntegral();

// Get uint64_t values, because different bitwidths would lead to an assertion
// in APInt::uge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) {
return;
}

QualType SourceType = MatchedCast->getSubExpr()->getType();
const QualType SourceType = MatchedCast->getSubExpr()->getType();

if (MatchedCast->getCastKind() == CK_BaseToDerived) {
const auto *SourceDecl = SourceType->getPointeeCXXRecordDecl();
Expand All @@ -58,7 +58,7 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) {
// Leave type spelling exactly as it was (unlike
// getTypeAsWritten().getAsString() which would spell enum types 'enum
// X').
StringRef DestTypeString = Lexer::getSourceText(
const StringRef DestTypeString = Lexer::getSourceText(
CharSourceRange::getTokenRange(
MatchedCast->getLParenLoc().getLocWithOffset(1),
MatchedCast->getRParenLoc().getLocWithOffset(-1)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct InitializerInsertion {
assert(!Initializers.empty() && "No initializers to insert");
std::string Code;
llvm::raw_string_ostream Stream(Code);
std::string Joined =
const std::string Joined =
llvm::join(Initializers.begin(), Initializers.end(), "(), ");
switch (Placement) {
case InitializerPlacement::New:
Expand Down Expand Up @@ -434,7 +434,7 @@ static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment) {
void ProTypeMemberInitCheck::checkMissingMemberInitializer(
ASTContext &Context, const CXXRecordDecl &ClassDecl,
const CXXConstructorDecl *Ctor) {
bool IsUnion = ClassDecl.isUnion();
const bool IsUnion = ClassDecl.isUnion();

if (IsUnion && ClassDecl.hasInClassInitializer())
return;
Expand Down Expand Up @@ -583,7 +583,7 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(

void ProTypeMemberInitCheck::checkUninitializedTrivialType(
const ASTContext &Context, const VarDecl *Var) {
DiagnosticBuilder Diag =
const DiagnosticBuilder Diag =
diag(Var->getBeginLoc(), "uninitialized record type: %0") << Var;

Diag << FixItHint::CreateInsertion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ProTypeStaticCastDowncastCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedCast = Result.Nodes.getNodeAs<CXXStaticCastExpr>("cast");

QualType SourceType = MatchedCast->getSubExpr()->getType();
const QualType SourceType = MatchedCast->getSubExpr()->getType();
const auto *SourceDecl = SourceType->getPointeeCXXRecordDecl();
if (!SourceDecl) // The cast is from object to reference
SourceDecl = SourceType->getAsCXXRecordDecl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ static constexpr StringRef VaArgWarningMessage =

namespace {
AST_MATCHER(QualType, isVAList) {
ASTContext &Context = Finder->getASTContext();
QualType Desugar = Node.getDesugaredType(Context);
QualType NodeTy = Node.getUnqualifiedType();
const ASTContext &Context = Finder->getASTContext();
const QualType Desugar = Node.getDesugaredType(Context);
const QualType NodeTy = Node.getUnqualifiedType();

auto CheckVaList = [](QualType NodeTy, QualType Expected,
const ASTContext &Context) {
Expand All @@ -88,7 +88,8 @@ AST_MATCHER(QualType, isVAList) {
// type. Some targets implements va_list as 'char *' or 'void *'.
// In these cases we need to remove all typedefs one by one to check this.
using BuiltinVaListKind = TargetInfo::BuiltinVaListKind;
BuiltinVaListKind VaListKind = Context.getTargetInfo().getBuiltinVaListKind();
const BuiltinVaListKind VaListKind =
Context.getTargetInfo().getBuiltinVaListKind();
if (VaListKind == BuiltinVaListKind::CharPtrBuiltinVaList ||
VaListKind == BuiltinVaListKind::VoidPtrBuiltinVaList) {
if (CheckVaList(NodeTy, Context.getBuiltinVaListType(), Context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AST_MATCHER_P2(Stmt, argumentOf, bool, AllowPartialMove, StatementMatcher,
void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));

StatementMatcher MoveCallMatcher =
const StatementMatcher MoveCallMatcher =
callExpr(
argumentCountIs(1),
anyOf(callee(functionDecl(hasName(MoveFunction))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ join(ArrayRef<SpecialMemberFunctionsCheck::SpecialMemberFunctionKind> SMFS,
llvm::raw_string_ostream Stream(Buffer);

Stream << toString(SMFS[0]);
size_t LastIndex = SMFS.size() - 1;
const size_t LastIndex = SMFS.size() - 1;
for (size_t I = 1; I < LastIndex; ++I) {
Stream << ", " << toString(SMFS[I]);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ void SpecialMemberFunctionsCheck::check(
StoreMember({DestructorType, Dtor->isDeleted()});
}

std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
const std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
Matchers = {{"copy-ctor", SpecialMemberFunctionKind::CopyConstructor},
{"copy-assign", SpecialMemberFunctionKind::CopyAssignment},
{"move-ctor", SpecialMemberFunctionKind::MoveConstructor},
Expand Down Expand Up @@ -202,7 +202,7 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
MissingMembers.push_back(Kind2);
};

bool RequireThree =
const bool RequireThree =
HasMember(SpecialMemberFunctionKind::NonDefaultDestructor) ||
(!AllowSoleDefaultDtor &&
(HasMember(SpecialMemberFunctionKind::Destructor) ||
Expand All @@ -212,10 +212,11 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
HasMember(SpecialMemberFunctionKind::MoveAssignment);

bool RequireFive = (!AllowMissingMoveFunctions && RequireThree &&
getLangOpts().CPlusPlus11) ||
HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
HasMember(SpecialMemberFunctionKind::MoveAssignment);
const bool RequireFive =
(!AllowMissingMoveFunctions && RequireThree &&
getLangOpts().CPlusPlus11) ||
HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
HasMember(SpecialMemberFunctionKind::MoveAssignment);

if (RequireThree) {
if (!HasMember(SpecialMemberFunctionKind::Destructor) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct DenseMapInfo<
assert(Val != getEmptyKey() && "Cannot hash the empty key!");
assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");

std::hash<ClassDefId::second_type> SecondHash;
const std::hash<ClassDefId::second_type> SecondHash;
return Val.first.getHashValue() + SecondHash(Val.second);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
if (Destructor.getLocation().isMacroID())
return std::nullopt;

SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
SourceLocation VirtualBeginSpellingLoc =
const SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
const SourceLocation VirtualBeginSpellingLoc =
SM.getSpellingLoc(Destructor.getBeginLoc());
SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
const SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
Lexer::MeasureTokenLength(VirtualBeginSpellingLoc, SM, LangOpts));

/// Range ends with \c StartOfNextToken so that any whitespace after \c
Expand All @@ -68,7 +68,7 @@ getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
Lexer::findNextToken(VirtualEndLoc, SM, LangOpts);
if (!NextToken)
return std::nullopt;
SourceLocation StartOfNextToken = NextToken->getLocation();
const SourceLocation StartOfNextToken = NextToken->getLocation();

return CharSourceRange::getCharRange(VirtualBeginLoc, StartOfNextToken);
}
Expand All @@ -79,7 +79,7 @@ getPublicASDecl(const CXXRecordDecl &StructOrClass) {
AS{StructOrClass.decls_begin()},
ASEnd{StructOrClass.decls_end()};
AS != ASEnd; ++AS) {
AccessSpecDecl *ASDecl = *AS;
const AccessSpecDecl *ASDecl = *AS;
if (ASDecl->getAccess() == AccessSpecifier::AS_public)
return ASDecl;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ static std::string getSourceText(const CXXDestructorDecl &Destructor) {

static std::string eraseKeyword(std::string &DestructorString,
const std::string &Keyword) {
size_t KeywordIndex = DestructorString.find(Keyword);
const size_t KeywordIndex = DestructorString.find(Keyword);
if (KeywordIndex != std::string::npos)
DestructorString.erase(KeywordIndex, Keyword.length());
return DestructorString;
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/custom/QueryCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parseQuery(const ClangTidyOptions::CustomCheckValue &V,
clang::query::QuerySession QS({});
llvm::StringRef QueryStringRef{V.Query};
while (!QueryStringRef.empty()) {
query::QueryRef Q = query::QueryParser::parse(QueryStringRef, QS);
const query::QueryRef Q = query::QueryParser::parse(QueryStringRef, QS);
switch (Q->Kind) {
case query::QK_Match: {
const auto &MatchQuery = llvm::cast<query::MatchQuery>(*Q);
Expand Down Expand Up @@ -126,11 +126,11 @@ void QueryCheck::registerMatchers(MatchFinder *Finder) {
void QueryCheck::check(const MatchFinder::MatchResult &Result) {
auto Emit = [this](const DiagMaps &DiagMaps, const std::string &BindName,
const DynTypedNode &Node, DiagnosticIDs::Level Level) {
DiagMaps::const_iterator DiagMapIt = DiagMaps.find(Level);
const DiagMaps::const_iterator DiagMapIt = DiagMaps.find(Level);
if (DiagMapIt == DiagMaps.end())
return;
const BindNameMapToDiagMessage &BindNameMap = DiagMapIt->second;
BindNameMapToDiagMessage::const_iterator BindNameMapIt =
const BindNameMapToDiagMessage::const_iterator BindNameMapIt =
BindNameMap.find(BindName);
if (BindNameMapIt == BindNameMap.end())
return;
Expand Down
Loading