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
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool rangeIsEntirelyWithinMacroArgument(SourceRange Range,
// Check if the range is entirely contained within a macro argument.
SourceLocation MacroArgExpansionStartForRangeBegin;
SourceLocation MacroArgExpansionStartForRangeEnd;
bool RangeIsEntirelyWithinMacroArgument =
const bool RangeIsEntirelyWithinMacroArgument =
SM &&
SM->isMacroArgExpansion(Range.getBegin(),
&MacroArgExpansionStartForRangeBegin) &&
Expand Down
12 changes: 7 additions & 5 deletions clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ FixItHint BraceInsertionHints::closingBraceFixIt() const {
static tok::TokenKind getTokenKind(SourceLocation Loc, const SourceManager &SM,
const LangOptions &LangOpts) {
Token Tok;
SourceLocation Beginning = Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
const SourceLocation Beginning =
Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
const bool Invalid = Lexer::getRawToken(Beginning, Tok, SM, LangOpts);
assert(!Invalid && "Expected a valid token.");

Expand Down Expand Up @@ -77,15 +78,16 @@ static SourceLocation findEndLocation(const Stmt &S, const SourceManager &SM,
// EOL, insert brace before.
break;
}
tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
const tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
if (TokKind != tok::comment) {
// Non-comment token, insert brace before.
break;
}

SourceLocation TokEndLoc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
SourceRange TokRange(Loc, TokEndLoc);
StringRef Comment = Lexer::getSourceText(
const SourceLocation TokEndLoc =
Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
const SourceRange TokRange(Loc, TokEndLoc);
const StringRef Comment = Lexer::getSourceText(
CharSourceRange::getTokenRange(TokRange), SM, LangOpts);
if (Comment.starts_with("/*") && Comment.contains('\n')) {
// Multi-line block comment, insert brace before.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static bool hasSameParameterTypes(const CXXMethodDecl &D,
static const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) {
assert(!D.isConst());

DeclContext::lookup_result LookupResult =
const DeclContext::lookup_result LookupResult =
D.getParent()->lookup(D.getNameInfo().getName());
if (LookupResult.isSingleResult()) {
// No overload.
Expand Down
31 changes: 17 additions & 14 deletions clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ ExceptionAnalyzer::ExceptionInfo::filterByCatch(const Type *HandlerTy,
llvm::SmallVector<const Type *, 8> TypesToDelete;
for (const auto &ThrownException : ThrownExceptions) {
const Type *ExceptionTy = ThrownException.getFirst();
CanQualType ExceptionCanTy = ExceptionTy->getCanonicalTypeUnqualified();
CanQualType HandlerCanTy = HandlerTy->getCanonicalTypeUnqualified();
const CanQualType ExceptionCanTy =
ExceptionTy->getCanonicalTypeUnqualified();
const CanQualType HandlerCanTy = HandlerTy->getCanonicalTypeUnqualified();

// The handler is of type cv T or cv T& and E and T are the same type
// (ignoring the top-level cv-qualifiers) ...
Expand Down Expand Up @@ -476,7 +477,7 @@ ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException(
// For a constructor, we also have to check the initializers.
if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Func)) {
for (const CXXCtorInitializer *Init : Ctor->inits()) {
ExceptionInfo Excs =
const ExceptionInfo Excs =
throwsException(Init->getInit(), Caught, CallStack);
Result.merge(Excs);
}
Expand Down Expand Up @@ -533,7 +534,7 @@ ExceptionAnalyzer::throwsException(const Stmt *St,

// Everything is caught through 'catch(...)'.
if (!Catch->getExceptionDecl()) {
ExceptionInfo Rethrown = throwsException(
const ExceptionInfo Rethrown = throwsException(
Catch->getHandlerBlock(), Uncaught.getExceptions(), CallStack);
Results.merge(Rethrown);
Uncaught.clear();
Expand All @@ -554,7 +555,7 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
Uncaught.filterByCatch(CaughtType,
Catch->getExceptionDecl()->getASTContext());
if (!FilteredExceptions.empty()) {
ExceptionInfo Rethrown = throwsException(
const ExceptionInfo Rethrown = throwsException(
Catch->getHandlerBlock(), FilteredExceptions, CallStack);
Results.merge(Rethrown);
}
Expand All @@ -563,44 +564,46 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
Results.merge(Uncaught);
} else if (const auto *Call = dyn_cast<CallExpr>(St)) {
if (const FunctionDecl *Func = Call->getDirectCallee()) {
ExceptionInfo Excs =
const ExceptionInfo Excs =
throwsException(Func, Caught, CallStack, Call->getBeginLoc());
Results.merge(Excs);
}
} else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) {
ExceptionInfo Excs = throwsException(Construct->getConstructor(), Caught,
CallStack, Construct->getBeginLoc());
const ExceptionInfo Excs =
throwsException(Construct->getConstructor(), Caught, CallStack,
Construct->getBeginLoc());
Results.merge(Excs);
} else if (const auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(St)) {
ExceptionInfo Excs =
const ExceptionInfo Excs =
throwsException(DefaultInit->getExpr(), Caught, CallStack);
Results.merge(Excs);
} else if (const auto *Coro = dyn_cast<CoroutineBodyStmt>(St)) {
for (const Stmt *Child : Coro->childrenExclBody()) {
if (Child != Coro->getExceptionHandler()) {
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
const ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
Results.merge(Excs);
}
}
ExceptionInfo Excs = throwsException(Coro->getBody(), Caught, CallStack);
const ExceptionInfo Excs =
throwsException(Coro->getBody(), Caught, CallStack);
Results.merge(throwsException(Coro->getExceptionHandler(),
Excs.getExceptions(), CallStack));
for (const auto &Exception : Excs.getExceptions()) {
const Type *ExcType = Exception.getFirst();
if (const CXXRecordDecl *ThrowableRec = ExcType->getAsCXXRecordDecl()) {
ExceptionInfo DestructorExcs = throwsException(
const ExceptionInfo DestructorExcs = throwsException(
ThrowableRec->getDestructor(), Caught, CallStack, SourceLocation{});
Results.merge(DestructorExcs);
}
}
} else if (const auto *Lambda = dyn_cast<LambdaExpr>(St)) {
for (const Stmt *Init : Lambda->capture_inits()) {
ExceptionInfo Excs = throwsException(Init, Caught, CallStack);
const ExceptionInfo Excs = throwsException(Init, Caught, CallStack);
Results.merge(Excs);
}
} else {
for (const Stmt *Child : St->children()) {
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
const ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
Results.merge(Excs);
}
}
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ExceptionSpecAnalyzer::analyze(const FunctionDecl *FuncDecl) {
const auto [CacheEntry, NotFound] =
FunctionCache.try_emplace(FuncDecl, State::NotThrowing);
if (NotFound) {
ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
const ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
// Update result with calculated value
FunctionCache[FuncDecl] = State;
return State;
Expand Down Expand Up @@ -87,20 +87,20 @@ ExceptionSpecAnalyzer::analyzeRecord(const CXXRecordDecl *RecordDecl,
return analyze(MethodDecl);

for (const auto &BaseSpec : RecordDecl->bases()) {
State Result = analyzeBase(BaseSpec, Kind);
const State Result = analyzeBase(BaseSpec, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}

for (const auto &BaseSpec : RecordDecl->vbases()) {
State Result = analyzeBase(BaseSpec, Kind);
const State Result = analyzeBase(BaseSpec, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}

for (const auto *FDecl : RecordDecl->fields())
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitField()) {
State Result = analyzeFieldDecl(FDecl, Kind);
const State Result = analyzeFieldDecl(FDecl, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}
Expand Down
7 changes: 4 additions & 3 deletions clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ static SmallVector<const Stmt *, 1> getParentStmts(const Stmt *S,
ASTContext *Context) {
SmallVector<const Stmt *, 1> Result;

TraversalKindScope RAII(*Context, TK_AsIs);
const TraversalKindScope RAII(*Context, TK_AsIs);
DynTypedNodeList Parents = Context->getParents(*S);

SmallVector<DynTypedNode, 1> NodesToProcess(Parents.begin(), Parents.end());

while (!NodesToProcess.empty()) {
DynTypedNode Node = NodesToProcess.back();
const DynTypedNode Node = NodesToProcess.back();
NodesToProcess.pop_back();

if (const auto *S = Node.get<Stmt>()) {
Expand Down Expand Up @@ -95,7 +95,8 @@ bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const {
return true;
}

SmallVector<const Stmt *, 1> BeforeParents = getParentStmts(Before, Context);
const SmallVector<const Stmt *, 1> BeforeParents =
getParentStmts(Before, Context);

// Since C++17, the callee of a call expression is guaranteed to be sequenced
// before all of the arguments.
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ namespace clang::tidy::utils {

bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
const SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
return isFileExtension(SM.getFilename(ExpansionLoc), HeaderFileExtensions);
}

bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
const PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
return isFileExtension(PresumedLocation.getFilename(), HeaderFileExtensions);
}

bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
const SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
return isFileExtension(SM.getFilename(SpellingLoc), HeaderFileExtensions);
}

bool parseFileExtensions(StringRef AllFileExtensions,
FileExtensionsSet &FileExtensions,
StringRef Delimiters) {
SmallVector<StringRef, 5> Suffixes;
for (char Delimiter : Delimiters) {
for (const char Delimiter : Delimiters) {
if (AllFileExtensions.contains(Delimiter)) {
AllFileExtensions.split(Suffixes, Delimiter);
break;
}
}

FileExtensions.clear();
for (StringRef Suffix : Suffixes) {
for (const StringRef Suffix : Suffixes) {
StringRef Extension = Suffix.trim();
if (!llvm::all_of(Extension, isAlphanumeric))
return false;
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ changePointer(const VarDecl &Var, Qualifiers::TQ Qualifier, const Type *Pointee,
// the `*` token and placing the `const` left of it.
// (`int const* p = nullptr;`)
if (QualPolicy == QualifierPolicy::Right) {
SourceLocation BeforeStar = lexer::findPreviousTokenKind(
const SourceLocation BeforeStar = lexer::findPreviousTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::star);
if (locDangerous(BeforeStar))
Expand All @@ -161,7 +161,7 @@ changePointer(const VarDecl &Var, Qualifiers::TQ Qualifier, const Type *Pointee,
// is the same as 'QualPolicy == Right && isValueType(Pointee)'.
// The `const` must be left of the last `*` token.
// (`int * const* p = nullptr;`)
SourceLocation BeforeStar = lexer::findPreviousTokenKind(
const SourceLocation BeforeStar = lexer::findPreviousTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::star);
return fixIfNotDangerous(BeforeStar, buildQualifier(Qualifier, true));
Expand All @@ -178,7 +178,7 @@ changeReferencee(const VarDecl &Var, Qualifiers::TQ Qualifier, QualType Pointee,
return fixIfNotDangerous(Var.getTypeSpecStartLoc(),
buildQualifier(Qualifier));

SourceLocation BeforeRef = lexer::findPreviousAnyTokenKind(
const SourceLocation BeforeRef = lexer::findPreviousAnyTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::amp, tok::ampamp);
std::optional<SourceLocation> IgnoredParens =
Expand All @@ -201,7 +201,7 @@ std::optional<FixItHint> addQualifierToVarDecl(const VarDecl &Var,
QualTarget == QualifierTarget::Value) &&
"Unexpected Target");

QualType ParenStrippedType = Var.getType().IgnoreParens();
const QualType ParenStrippedType = Var.getType().IgnoreParens();
if (isValueType(ParenStrippedType))
return changeValue(Var, Qualifier, QualTarget, QualPolicy, Context);

Expand Down
10 changes: 6 additions & 4 deletions clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ FormatStringConverter::formatStringContainsUnreplaceableMacro(
// inhibit conversion. The whole format string will appear to come from that
// macro, as will the function call.
std::optional<StringRef> MaybeSurroundingMacroName;
if (SourceLocation BeginCallLoc = Call->getBeginLoc();
if (const SourceLocation BeginCallLoc = Call->getBeginLoc();
BeginCallLoc.isMacroID())
MaybeSurroundingMacroName =
Lexer::getImmediateMacroName(BeginCallLoc, SM, PP.getLangOpts());
Expand Down Expand Up @@ -283,7 +283,8 @@ FormatStringConverter::formatStringContainsUnreplaceableMacro(

void FormatStringConverter::emitAlignment(const PrintfSpecifier &FS,
std::string &FormatSpec) {
ConversionSpecifier::Kind ArgKind = FS.getConversionSpecifier().getKind();
const ConversionSpecifier::Kind ArgKind =
FS.getConversionSpecifier().getKind();

// We only care about alignment if a field width is specified
if (FS.getFieldWidth().getHowSpecified() != OptionalAmount::NotSpecified) {
Expand Down Expand Up @@ -499,7 +500,8 @@ bool FormatStringConverter::emitIntegerArgument(
/// @returns true on success, false on failure
bool FormatStringConverter::emitType(const PrintfSpecifier &FS, const Expr *Arg,
std::string &FormatSpec) {
ConversionSpecifier::Kind ArgKind = FS.getConversionSpecifier().getKind();
const ConversionSpecifier::Kind ArgKind =
FS.getConversionSpecifier().getKind();
switch (ArgKind) {
case ConversionSpecifier::Kind::sArg:
emitStringArgument(FS.getArgIndex() + ArgsOffset, Arg);
Expand Down Expand Up @@ -798,7 +800,7 @@ void FormatStringConverter::applyFixes(DiagnosticBuilder &Diag,
}

for (const auto &[ArgIndex, Replacement] : ArgFixes) {
SourceLocation AfterOtherSide =
const SourceLocation AfterOtherSide =
Lexer::findNextToken(Args[ArgIndex]->getEndLoc(), SM, LangOpts)
->getLocation();

Expand Down
Loading