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
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {

CharSourceRange ReplaceRange = getReplaceRange(CastExpr);

bool FnToFnCast =
const bool FnToFnCast =
IsFunction(SourceTypeAsWritten) && IsFunction(DestTypeAsWritten);

const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() &&
Expand Down Expand Up @@ -239,8 +239,8 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
if (DestType->isReferenceType()) {
QualType Dest = DestType.getNonReferenceType();
QualType Source = SourceType.getNonReferenceType();
const QualType Dest = DestType.getNonReferenceType();
const QualType Source = SourceType.getNonReferenceType();
if (Source == Dest.withConst() ||
SourceType.getNonReferenceType() == DestType.getNonReferenceType()) {
ReplaceWithNamedCast("const_cast");
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ using namespace clang::ast_matchers;
namespace clang::tidy::google::objc {

static bool isMessageExpressionInsideMacro(const ObjCMessageExpr *Expr) {
SourceLocation ReceiverLocation = Expr->getReceiverRange().getBegin();
const SourceLocation ReceiverLocation = Expr->getReceiverRange().getBegin();
if (ReceiverLocation.isMacroID())
return true;

SourceLocation SelectorLocation = Expr->getSelectorStartLoc();
const SourceLocation SelectorLocation = Expr->getSelectorStartLoc();
if (SelectorLocation.isMacroID())
return true;

Expand Down Expand Up @@ -58,7 +58,7 @@ static bool isInitMethodAvailable(const ObjCInterfaceDecl *ClassDecl) {
static StringRef getReceiverString(SourceRange ReceiverRange,
const SourceManager &SM,
const LangOptions &LangOpts) {
CharSourceRange CharRange = Lexer::makeFileCharRange(
const CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(ReceiverRange), SM, LangOpts);
return Lexer::getSourceText(CharRange, SM, LangOpts);
}
Expand All @@ -77,13 +77,13 @@ static FixItHint getCallFixItHint(const ObjCMessageExpr *Expr,
if (FoundClassFactory != ClassToFactoryMethodMap.end()) {
StringRef ClassName = FoundClassFactory->first;
StringRef FactorySelector = FoundClassFactory->second;
std::string NewCall =
const std::string NewCall =
std::string(llvm::formatv("[{0} {1}]", ClassName, FactorySelector));
return FixItHint::CreateReplacement(Expr->getSourceRange(), NewCall);
}

if (isInitMethodAvailable(Expr->getReceiverInterface())) {
std::string NewCall =
const std::string NewCall =
std::string(llvm::formatv("[[{0} alloc] init]", Receiver));
return FixItHint::CreateReplacement(Expr->getSourceRange(), NewCall);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void AvoidThrowingObjCExceptionCheck::check(
// If the match location was in a macro, check if the macro was in a system
// header.
if (SourceLoc.isMacroID()) {
SourceManager &SM = *Result.SourceManager;
const SourceManager &SM = *Result.SourceManager;
auto MacroLoc = SM.getImmediateMacroCallerLoc(SourceLoc);

// Matches in system header macros should be ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
void MacroExpands(const Token &MacroNameToken,
const MacroDefinition &MacroDefinition, SourceRange Range,
const MacroArgs *Args) override {
IdentifierInfo *NameIdentifierInfo = MacroNameToken.getIdentifierInfo();
const IdentifierInfo *NameIdentifierInfo =
MacroNameToken.getIdentifierInfo();
if (!NameIdentifierInfo)
return;
StringRef MacroName = NameIdentifierInfo->getName();
const StringRef MacroName = NameIdentifierInfo->getName();
if (!isGoogletestTestMacro(MacroName) || !Args ||
Args->getNumMacroArguments() < 2)
return;
const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
const Token *TestNameToken = Args->getUnexpArgument(1);
if (!TestSuiteNameToken || !TestNameToken)
return;
std::string TestSuiteNameMaybeDisabled =
const std::string TestSuiteNameMaybeDisabled =
PP->getSpelling(*TestSuiteNameToken);
StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
TestSuiteName.consume_front(KDisabledTestPrefix);
Expand All @@ -60,7 +61,7 @@ class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
"Googletest FAQ")
<< TestSuiteName;

std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
const std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
StringRef TestName = TestNameMaybeDisabled;
TestName.consume_front(KDisabledTestPrefix);
if (TestName.contains('_'))
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static SourceRange findToken(const SourceManager &Sources,
bool (*Pred)(const Token &)) {
if (StartLoc.isMacroID() || EndLoc.isMacroID())
return {};
FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
StringRef Buf = Sources.getBufferData(File);
const FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
const StringRef Buf = Sources.getBufferData(File);
const char *StartChar = Sources.getCharacterData(StartLoc);
Lexer Lex(StartLoc, LangOpts, StartChar, StartChar, Buf.end());
Lex.SetCommentRetentionState(true);
Expand Down Expand Up @@ -88,7 +88,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
if (Conversion->isOutOfLine())
return;
SourceLocation Loc = Conversion->getLocation();
const SourceLocation Loc = Conversion->getLocation();
// Ignore all macros until we learn to ignore specific ones (e.g. used in
// gmock to define matchers).
if (Loc.isMacroID())
Expand All @@ -105,15 +105,15 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {

const ExplicitSpecifier ExplicitSpec = Ctor->getExplicitSpecifier();

bool TakesInitializerList = isStdInitializerList(
const bool TakesInitializerList = isStdInitializerList(
Ctor->getParamDecl(0)->getType().getNonReferenceType());
if (ExplicitSpec.isExplicit() &&
(Ctor->isCopyOrMoveConstructor() || TakesInitializerList)) {
auto IsKwExplicit = [](const Token &Tok) {
return Tok.is(tok::raw_identifier) &&
Tok.getRawIdentifier() == "explicit";
};
SourceRange ExplicitTokenRange =
const SourceRange ExplicitTokenRange =
findToken(*Result.SourceManager, getLangOpts(),
Ctor->getOuterLocStart(), Ctor->getEndLoc(), IsKwExplicit);
StringRef ConstructorDescription;
Expand Down Expand Up @@ -149,7 +149,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {

const bool SingleArgument =
Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
SourceLocation Loc = Ctor->getLocation();
const SourceLocation Loc = Ctor->getLocation();
auto Diag =
diag(Loc, ExplicitExpr ? WithExpressionWarningMessage
: NoExpressionWarningMessage)
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static std::string validFunctionNameRegex(bool RequirePrefix) {
// If a prefix is required, the regex checks for a capital letter followed by
// another capital letter or number that is part of the prefix and another
// capital letter or number that begins the name following the prefix.
std::string FunctionNameMatcher =
const std::string FunctionNameMatcher =
std::string(RequirePrefix ? "[A-Z][A-Z0-9]+" : "") + "[A-Z][a-zA-Z0-9]*";
return std::string("::(") + FunctionNameMatcher + ")$";
}
Expand All @@ -48,13 +48,13 @@ static FixItHint generateFixItHint(const FunctionDecl *Decl) {
if (Decl->getStorageClass() != SC_Static)
return {};

StringRef Name = Decl->getName();
const StringRef Name = Decl->getName();
std::string NewName = Decl->getName().str();

size_t Index = 0;
bool AtWordBoundary = true;
while (Index < NewName.size()) {
char Ch = NewName[Index];
const char Ch = NewName[Index];
if (isalnum(Ch)) {
// Capitalize the first letter after every word boundary.
if (AtWordBoundary) {
Expand Down Expand Up @@ -101,7 +101,7 @@ void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
void FunctionNamingCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("function");

bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
const bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
diag(MatchedDecl->getLocation(),
"%select{static function|function in global namespace}1 named %0 must "
"%select{be in|have an appropriate prefix followed by}1 Pascal case as "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ static FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
return {};
}

char FC = Decl->getName()[0];
const char FC = Decl->getName()[0];
if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
// No fix available if first character is not alphabetical character, or it
// is a single-character variable, since it is difficult to determine the
// proper fix in this case. Users should create a proper variable name by
// their own.
return {};
}
char SC = Decl->getName()[1];
const char SC = Decl->getName()[1];
if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) {
// No fix available if the prefix is correct but the second character is
// not alphabetical, since it is difficult to determine the proper fix in
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {

void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
auto TL = *Result.Nodes.getNodeAs<TypeLoc>("tl");
SourceLocation Loc = TL.getBeginLoc();
const SourceLocation Loc = TL.getBeginLoc();

// Look through qualification.
if (auto QualLoc = TL.getAs<QualifiedTypeLoc>())
Expand All @@ -113,7 +113,7 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
if (!BuiltinLoc)
return;

Token Tok = getTokenAtLoc(Loc, Result, *IdentTable);
const Token Tok = getTokenAtLoc(Loc, Result, *IdentTable);
// Ensure the location actually points to one of the builting integral type
// names we're interested in. Otherwise, we might be getting this match from
// implicit code (e.g. an implicit assignment operator of a class containing
Expand Down Expand Up @@ -164,7 +164,7 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
!isAsciiIdentifierContinue(Data[Port.size()]))
return;

std::string Replacement =
const std::string Replacement =
((IsSigned ? SignedTypePrefix : UnsignedTypePrefix) + Twine(Width) +
TypeSuffix)
.str();
Expand Down
9 changes: 5 additions & 4 deletions clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {}

bool HandleComment(Preprocessor &PP, SourceRange Range) override {
StringRef Text =
const StringRef Text =
Lexer::getSourceText(CharSourceRange::getCharRange(Range),
PP.getSourceManager(), PP.getLangOpts());

SmallVector<StringRef, 4> Matches;
if (!TodoMatch.match(Text, &Matches))
return false;

StringRef Username = Matches[1];
StringRef Comment = Matches[3];
const StringRef Username = Matches[1];
const StringRef Comment = Matches[3];

if (!Username.empty())
return false;

std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str();
const std::string NewText =
("// TODO(" + Twine(User) + "): " + Comment).str();

Check.diag(Range.getBegin(), "missing username/bug in TODO")
<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(Range),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void UnnamedNamespaceInHeaderCheck::registerMatchers(
void UnnamedNamespaceInHeaderCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>("anonymousNamespace");
SourceLocation Loc = N->getBeginLoc();
const SourceLocation Loc = N->getBeginLoc();
if (!Loc.isValid())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UpgradeGoogletestCasePPCallback : public PPCallbacks {
// We check if the newly defined macro is one of the target replacements.
// This ensures that the check creates warnings only if it is including a
// recent enough version of Google Test.
llvm::StringRef FileName = PP->getSourceManager().getFilename(
const llvm::StringRef FileName = PP->getSourceManager().getFilename(
MD->getMacroInfo()->getDefinitionLoc());
ReplacementFound = FileName.ends_with("gtest/gtest-typed-test.h") &&
PP->getSpelling(MacroNameTok) == "TYPED_TEST_SUITE";
Expand Down Expand Up @@ -94,18 +94,18 @@ class UpgradeGoogletestCasePPCallback : public PPCallbacks {
if (!ReplacementFound)
return;

std::string Name = PP->getSpelling(MacroNameTok);
const std::string Name = PP->getSpelling(MacroNameTok);

std::optional<llvm::StringRef> Replacement = getNewMacroName(Name);
if (!Replacement)
return;

llvm::StringRef FileName = PP->getSourceManager().getFilename(
const llvm::StringRef FileName = PP->getSourceManager().getFilename(
MD.getMacroInfo()->getDefinitionLoc());
if (!FileName.ends_with("gtest/gtest-typed-test.h"))
return;

DiagnosticBuilder Diag = Check->diag(Loc, RenameCaseToSuiteMessage);
const DiagnosticBuilder Diag = Check->diag(Loc, RenameCaseToSuiteMessage);

if (Action == CheckAction::Rename)
Diag << FixItHint::CreateReplacement(
Expand Down Expand Up @@ -234,7 +234,7 @@ static bool isInInstantiation(const NodeType &Node,
template <typename NodeType>
static bool isInTemplate(const NodeType &Node,
const MatchFinder::MatchResult &Result) {
internal::Matcher<NodeType> IsInsideTemplate =
const internal::Matcher<NodeType> IsInsideTemplate =
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
return !match(IsInsideTemplate, Node, *Result.Context).empty();
}
Expand Down Expand Up @@ -340,7 +340,7 @@ void UpgradeGoogletestCaseCheck::check(const MatchFinder::MatchResult &Result) {
// will only be instantiated with the true type name, `TestSuite`.
}

DiagnosticBuilder Diag =
const DiagnosticBuilder Diag =
diag(ReplacementRange.getBegin(), RenameCaseToSuiteMessage);

ReplacementRange = Lexer::makeFileCharRange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void UsingNamespaceDirectiveCheck::registerMatchers(
void UsingNamespaceDirectiveCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace");
SourceLocation Loc = U->getBeginLoc();
const SourceLocation Loc = U->getBeginLoc();
if (U->isImplicit() || !Loc.isValid())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void ImplicitConversionInLoopCheck::reportAndFix(const ASTContext *Context,
const Expr *OperatorCall) {
// We only match on const ref, so we should print a const ref version of the
// type.
QualType ConstType = OperatorCall->getType().withConst();
QualType ConstRefType = Context->getLValueReferenceType(ConstType);
const QualType ConstType = OperatorCall->getType().withConst();
const QualType ConstRefType = Context->getLValueReferenceType(ConstType);
const char Message[] =
"the type of the loop variable %0 is different from the one returned "
"by the iterator and generates an implicit conversion; you can either "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {

// Store if the key type of the container is compatible with the value
// that is searched for.
QualType ValueType = AlgCall->getArg(2)->getType();
QualType KeyType =
const QualType ValueType = AlgCall->getArg(2)->getType();
const QualType KeyType =
IneffCont->getTemplateArgs()[0].getAsType().getCanonicalType();
const bool CompatibleTypes = areTypesCompatible(KeyType, ValueType);

Expand Down Expand Up @@ -104,8 +104,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
const auto *IneffContExpr = Result.Nodes.getNodeAs<Expr>("IneffContExpr");
FixItHint Hint;

SourceManager &SM = *Result.SourceManager;
LangOptions LangOpts = getLangOpts();
const SourceManager &SM = *Result.SourceManager;
const LangOptions LangOpts = getLangOpts();

CharSourceRange CallRange =
CharSourceRange::getTokenRange(AlgCall->getSourceRange());
Expand All @@ -128,13 +128,13 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
}

if (!CallRange.getBegin().isMacroID() && !Maplike && CompatibleTypes) {
StringRef ContainerText = Lexer::getSourceText(
const StringRef ContainerText = Lexer::getSourceText(
CharSourceRange::getTokenRange(IneffContExpr->getSourceRange()), SM,
LangOpts);
StringRef ParamText = Lexer::getSourceText(
const StringRef ParamText = Lexer::getSourceText(
CharSourceRange::getTokenRange(AlgParam->getSourceRange()), SM,
LangOpts);
std::string ReplacementText =
const std::string ReplacementText =
(llvm::Twine(ContainerText) + (PtrToContainer ? "->" : ".") +
AlgDecl->getName() + "(" + ParamText + ")")
.str();
Expand Down
Loading