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
20 changes: 10 additions & 10 deletions clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static SmallVector<BindArgument, 4>
buildBindArguments(const MatchFinder::MatchResult &Result,
const CallableInfo &Callable) {
SmallVector<BindArgument, 4> BindArguments;
static llvm::Regex MatchPlaceholder("^_([0-9]+)$");
static const llvm::Regex MatchPlaceholder("^_([0-9]+)$");

const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");

Expand All @@ -267,7 +267,7 @@ buildBindArguments(const MatchFinder::MatchResult &Result,
if (Callable.Type == CT_MemberFunction)
--ArgIndex;

bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
const bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
B.E = E;
B.SourceTokens = getSourceTextForExpr(Result, E);

Expand Down Expand Up @@ -340,13 +340,13 @@ static void addPlaceholderArgs(const LambdaProperties &LP,
MaxPlaceholderIt->PlaceHolderIndex == 0))
return;

size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
const size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
Stream << "(";
StringRef Delimiter = "";
for (size_t I = 1; I <= PlaceholderCount; ++I) {
Stream << Delimiter << "auto &&";

int ArgIndex = findPositionOfPlaceholderUse(Args, I);
const int ArgIndex = findPositionOfPlaceholderUse(Args, I);

if (ArgIndex != -1 && Args[ArgIndex].IsUsed)
Stream << " " << Args[ArgIndex].UsageIdentifier;
Expand Down Expand Up @@ -392,7 +392,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, size_t NumArgs) {
std::vector<const FunctionDecl *> Candidates;

for (const clang::CXXMethodDecl *Method : RecordDecl->methods()) {
OverloadedOperatorKind OOK = Method->getOverloadedOperator();
const OverloadedOperatorKind OOK = Method->getOverloadedOperator();

if (OOK != OverloadedOperatorKind::OO_Call)
continue;
Expand All @@ -410,7 +410,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, size_t NumArgs) {
continue;
const FunctionDecl *FD = FTD->getTemplatedDecl();

OverloadedOperatorKind OOK = FD->getOverloadedOperator();
const OverloadedOperatorKind OOK = FD->getOverloadedOperator();
if (OOK != OverloadedOperatorKind::OO_Call)
continue;

Expand Down Expand Up @@ -471,7 +471,7 @@ getCallMethodDecl(const MatchFinder::MatchResult &Result, CallableType Type,

if (Type == CT_Object) {
const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");
size_t NumArgs = BindCall->getNumArgs() - 1;
const size_t NumArgs = BindCall->getNumArgs() - 1;
return getCallOperator(Callee->getType()->getAsCXXRecordDecl(), NumArgs);
}

Expand All @@ -488,7 +488,7 @@ getCallMethodDecl(const MatchFinder::MatchResult &Result, CallableType Type,
static CallableType getCallableType(const MatchFinder::MatchResult &Result) {
const auto *CallableExpr = Result.Nodes.getNodeAs<Expr>("ref");

QualType QT = CallableExpr->getType();
const QualType QT = CallableExpr->getType();
if (QT->isMemberFunctionPointerType())
return CT_MemberFunction;

Expand Down Expand Up @@ -614,7 +614,7 @@ static void emitCaptureList(const LambdaProperties &LP,
if (B.CM == CM_None || !B.IsUsed)
continue;

StringRef Delimiter = AnyCapturesEmitted ? ", " : "";
const StringRef Delimiter = AnyCapturesEmitted ? ", " : "";

if (emitCapture(CaptureSet, Delimiter, B.CM, B.CE, B.CaptureIdentifier,
B.SourceTokens, Stream))
Expand Down Expand Up @@ -669,7 +669,7 @@ void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) {
emitCaptureList(LP, Result, Stream);
Stream << "]";

ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);
const ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);

addPlaceholderArgs(LP, Stream, PermissiveParameterList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ static bool locationsInSameFile(const SourceManager &Sources,
static StringRef getRawStringRef(const SourceRange &Range,
const SourceManager &Sources,
const LangOptions &LangOpts) {
CharSourceRange TextRange = Lexer::getAsCharRange(Range, Sources, LangOpts);
const CharSourceRange TextRange =
Lexer::getAsCharRange(Range, Sources, LangOpts);
return Lexer::getSourceText(TextRange, Sources, LangOpts);
}

Expand Down Expand Up @@ -56,15 +57,16 @@ SourceRange NS::getDefaultNamespaceBackRange() const {
SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
const LangOptions &LangOpts) const {
// Back from '}' to conditional '// namespace xxx'
SourceLocation Loc = front()->getRBraceLoc();
const SourceLocation Loc = front()->getRBraceLoc();
std::optional<Token> Tok =
utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
if (!Tok)
return getDefaultNamespaceBackRange();
if (Tok->getKind() != tok::TokenKind::comment)
return getDefaultNamespaceBackRange();
SourceRange TokRange = SourceRange{Tok->getLocation(), Tok->getEndLoc()};
StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
const SourceRange TokRange =
SourceRange{Tok->getLocation(), Tok->getEndLoc()};
const StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
NamespaceName CloseComment{"namespace "};
appendCloseComment(CloseComment);
// current fix hint in readability/NamespaceCommentCheck.cpp use single line
Expand Down Expand Up @@ -98,15 +100,15 @@ bool ConcatNestedNamespacesCheck::unsupportedNamespace(const NamespaceDecl &ND,
return true;
if (getLangOpts().CPlusPlus20) {
// C++20 support inline nested namespace
bool IsFirstNS = IsChild || !Namespaces.empty();
const bool IsFirstNS = IsChild || !Namespaces.empty();
return ND.isInlineNamespace() && !IsFirstNS;
}
return ND.isInlineNamespace();
}

bool ConcatNestedNamespacesCheck::singleNamedNamespaceChild(
const NamespaceDecl &ND) const {
NamespaceDecl::decl_range Decls = ND.decls();
const NamespaceDecl::decl_range Decls = ND.decls();
if (std::distance(Decls.begin(), Decls.end()) != 1)
return false;

Expand All @@ -121,7 +123,7 @@ void ConcatNestedNamespacesCheck::registerMatchers(

void ConcatNestedNamespacesCheck::reportDiagnostic(
const SourceManager &SM, const LangOptions &LangOpts) {
DiagnosticBuilder DB =
const DiagnosticBuilder DB =
diag(Namespaces.front().front()->getBeginLoc(),
"nested namespaces can be concatenated", DiagnosticIDs::Warning);

Expand All @@ -143,7 +145,7 @@ void ConcatNestedNamespacesCheck::reportDiagnostic(

// the last one should be handled specially
Fronts.pop_back();
SourceRange LastRBrace = Backs.pop_back_val();
const SourceRange LastRBrace = Backs.pop_back_val();

NamespaceName ConcatNameSpace{"namespace "};
for (const NS &NS : Namespaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
// 1. Insert std prefix for every such symbol occurrence.
// 2. Insert `using namespace std;` to the beginning of TU.
// 3. Do nothing and let the user deal with the migration himself.
SourceLocation DiagLoc = FilenameRange.getBegin();
const SourceLocation DiagLoc = FilenameRange.getBegin();
if (auto It = CStyledHeaderToCxx.find(FileName);
It != CStyledHeaderToCxx.end()) {
IncludesToBeProcessed.emplace_back(IncludeMarker{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {

void DeprecatedIosBaseAliasesCheck::check(
const MatchFinder::MatchResult &Result) {
SourceManager &SM = *Result.SourceManager;
const SourceManager &SM = *Result.SourceManager;

const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
StringRef TypeName = Typedef->getName();
const StringRef TypeName = Typedef->getName();
auto Replacement = getReplacementType(TypeName);

TypeLoc TL = *Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
Expand All @@ -55,7 +55,8 @@ void DeprecatedIosBaseAliasesCheck::check(
Fix = false;
}

SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
const SourceLocation EndLoc =
IoStateLoc.getLocWithOffset(TypeName.size() - 1);

if (Replacement) {
const char *FixName = *Replacement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool IntegralLiteralExpressionMatcher::unaryOperator() {
}

static LiteralSize literalTokenSize(const Token &Tok) {
unsigned int Length = Tok.getLength();
const unsigned int Length = Tok.getLength();
if (Length <= 1)
return LiteralSize::Int;

Expand Down
47 changes: 24 additions & 23 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
/// - The index variable is only used as an array index.
/// - All arrays indexed by the loop are the same.
static StatementMatcher makeArrayLoopMatcher() {
StatementMatcher ArrayBoundMatcher =
const StatementMatcher ArrayBoundMatcher =
expr(hasType(isInteger())).bind(ConditionBoundName);

return forStmt(unless(isInTemplateInstantiation()),
Expand Down Expand Up @@ -168,7 +168,7 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
auto EndNameMatcherStd = IsReverse ? hasAnyName("::std::rend", "::std::crend")
: hasAnyName("::std::end", "::std::cend");

StatementMatcher BeginCallMatcher =
const StatementMatcher BeginCallMatcher =
expr(anyOf(cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(BeginNameMatcher))),
callExpr(argumentCountIs(1),
Expand All @@ -177,37 +177,37 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
callee(functionDecl(BeginNameMatcherStd)))))
.bind(BeginCallName);

DeclarationMatcher InitDeclMatcher =
const DeclarationMatcher InitDeclMatcher =
varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
materializeTemporaryExpr(
ignoringParenImpCasts(BeginCallMatcher)),
hasDescendant(BeginCallMatcher))))
.bind(InitVarName);

DeclarationMatcher EndDeclMatcher =
const DeclarationMatcher EndDeclMatcher =
varDecl(hasInitializer(anything())).bind(EndVarName);

StatementMatcher EndCallMatcher = expr(anyOf(
const StatementMatcher EndCallMatcher = expr(anyOf(
cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(EndNameMatcher))),
callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcher)),
usesADL()),
callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcherStd)))));

StatementMatcher IteratorBoundMatcher =
const StatementMatcher IteratorBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
ignoringParenImpCasts(expr(EndCallMatcher).bind(EndCallName)),
materializeTemporaryExpr(ignoringParenImpCasts(
expr(EndCallMatcher).bind(EndCallName)))));

StatementMatcher IteratorComparisonMatcher = expr(ignoringParenImpCasts(
const StatementMatcher IteratorComparisonMatcher = expr(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(InitVarName))))));

// This matcher tests that a declaration is a CXXRecordDecl that has an
// overloaded operator*(). If the operator*() returns by value instead of by
// reference then the return type is tagged with DerefByValueResultName.
internal::Matcher<VarDecl> TestDerefReturnsByValue =
const internal::Matcher<VarDecl> TestDerefReturnsByValue =
hasType(hasUnqualifiedDesugaredType(
recordType(hasDeclaration(cxxRecordDecl(hasMethod(cxxMethodDecl(
hasOverloadedOperatorName("*"),
Expand Down Expand Up @@ -280,7 +280,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
// FIXME: Also, a record doesn't necessarily need begin() and end(). Free
// functions called begin() and end() taking the container as an argument
// are also allowed.
TypeMatcher RecordWithBeginEnd = qualType(anyOf(
const TypeMatcher RecordWithBeginEnd = qualType(anyOf(
qualType(isConstQualified(),
hasUnqualifiedDesugaredType(recordType(hasDeclaration(
cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
Expand All @@ -295,7 +295,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
hasMethod(hasName("end"))))))))) // qualType
));

StatementMatcher SizeCallMatcher = expr(anyOf(
const StatementMatcher SizeCallMatcher = expr(anyOf(
cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(hasAnyName("size", "length"))),
on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
Expand All @@ -310,10 +310,10 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
explicitCastExpr(hasSourceExpression(ignoringParenImpCasts(
expr(SizeCallMatcher).bind(EndCallName))))));

DeclarationMatcher EndDeclMatcher =
const DeclarationMatcher EndDeclMatcher =
varDecl(hasInitializer(EndInitMatcher)).bind(EndVarName);

StatementMatcher IndexBoundMatcher =
const StatementMatcher IndexBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
EndInitMatcher));
Expand Down Expand Up @@ -620,7 +620,7 @@ void LoopConvertCheck::getAliasRange(SourceManager &SM, SourceRange &Range) {
SM.getCharacterData(Range.getEnd().getLocWithOffset(1), &Invalid);
if (Invalid)
return;
unsigned Offset = std::strspn(TextAfter, " \t\r\n");
const unsigned Offset = std::strspn(TextAfter, " \t\r\n");
Range =
SourceRange(Range.getBegin(), Range.getEnd().getLocWithOffset(Offset));
}
Expand All @@ -633,7 +633,7 @@ void LoopConvertCheck::doConversion(
const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
const ForStmt *Loop, RangeDescriptor Descriptor) {
std::string VarNameOrStructuredBinding;
bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
const bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
bool AliasVarIsRef = false;
bool CanCopy = true;
std::vector<FixItHint> FixIts;
Expand Down Expand Up @@ -743,7 +743,7 @@ void LoopConvertCheck::doConversion(
}

// Now, we need to construct the new range expression.
SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
const SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());

QualType Type = Context->getAutoDeductType();
if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
Expand All @@ -753,14 +753,15 @@ void LoopConvertCheck::doConversion(
// If the new variable name is from the aliased variable, then the reference
// type for the new variable should only be used if the aliased variable was
// declared as a reference.
bool IsCheapToCopy =
const bool IsCheapToCopy =
!Descriptor.ElemType.isNull() &&
Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
!Descriptor.ElemType->isDependentSizedArrayType() &&
// TypeInfo::Width is in bits.
Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
(Descriptor.DerefByConstRef && IsCheapToCopy));
const bool UseCopy =
CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
(Descriptor.DerefByConstRef && IsCheapToCopy));

if (!UseCopy) {
if (Descriptor.DerefByConstRef) {
Expand Down Expand Up @@ -866,7 +867,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context,
// The matchers for iterator loops provide bound nodes to obtain this
// information.
const auto *InitVar = Nodes.getNodeAs<VarDecl>(InitVarName);
QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
const QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
const auto *DerefByValueType =
Nodes.getNodeAs<QualType>(DerefByValueResultName);
Descriptor.DerefByValue = DerefByValueType;
Expand Down Expand Up @@ -934,12 +935,12 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,

// FIXME: Try to put most of this logic inside a matcher.
if (FixerKind == LFK_Iterator || FixerKind == LFK_ReverseIterator) {
QualType InitVarType = InitVar->getType();
QualType CanonicalInitVarType = InitVarType.getCanonicalType();
const QualType InitVarType = InitVar->getType();
const QualType CanonicalInitVarType = InitVarType.getCanonicalType();

const auto *BeginCall = Nodes.getNodeAs<CallExpr>(BeginCallName);
assert(BeginCall && "Bad Callback. No begin call expression");
QualType CanonicalBeginType =
const QualType CanonicalBeginType =
BeginCall->getDirectCallee()->getReturnType().getCanonicalType();
if (CanonicalBeginType->isPointerType() &&
CanonicalInitVarType->isPointerType()) {
Expand Down Expand Up @@ -1054,7 +1055,7 @@ void LoopConvertCheck::check(const MatchFinder::MatchResult &Result) {
}

// Find out which qualifiers we have to use in the loop range.
TraversalKindScope RAII(*Context, TK_AsIs);
const TraversalKindScope RAII(*Context, TK_AsIs);
const UsageResult &Usages = Finder.getUsages();
determineRangeDescriptor(Context, Nodes, Loop, FixerKind, ContainerExpr,
Usages, Descriptor);
Expand Down
Loading