diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/abseil')
20 files changed, 62 insertions, 55 deletions
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h index 2ae3c00..982774c 100644 --- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h +++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H + #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include <algorithm> @@ -31,7 +34,7 @@ AST_POLYMORPHIC_MATCHER( isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) { auto &SourceManager = Finder->getASTContext().getSourceManager(); - SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc()); + const SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc()); if (Loc.isInvalid()) return false; OptionalFileEntryRef FileEntry = @@ -42,7 +45,7 @@ AST_POLYMORPHIC_MATCHER( // [absl-library] is AbseilLibraries list entry. StringRef Path = FileEntry->getName(); static constexpr llvm::StringLiteral AbslPrefix("absl/"); - size_t PrefixPosition = Path.find(AbslPrefix); + const size_t PrefixPosition = Path.find(AbslPrefix); if (PrefixPosition == StringRef::npos) return false; Path = Path.drop_front(PrefixPosition + AbslPrefix.size()); @@ -57,3 +60,5 @@ AST_POLYMORPHIC_MATCHER( } } // namespace clang::ast_matchers + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp index 4e1bd3a..421e5973 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp @@ -21,7 +21,7 @@ void DurationAdditionCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( binaryOperator(hasOperatorName("+"), hasEitherOperand(expr(ignoringParenImpCasts( - callExpr(callee(functionDecl(TimeConversionFunction()) + callExpr(callee(functionDecl(timeConversionFunction()) .bind("function_decl"))) .bind("call"))))) .bind("binop"), @@ -41,7 +41,7 @@ void DurationAdditionCheck::check(const MatchFinder::MatchResult &Result) { if (!Scale) return; - llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale); + const llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale); FixItHint Hint; if (Call == Binop->getLHS()->IgnoreParenImpCasts()) { diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h index b728118..f5bab53 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H #include "../ClangTidyCheck.h" @@ -31,4 +31,4 @@ public: } // namespace clang::tidy::abseil -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H diff --git a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp index cb8a478..f008777 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp @@ -17,7 +17,7 @@ namespace clang::tidy::abseil { void DurationComparisonCheck::registerMatchers(MatchFinder *Finder) { auto Matcher = expr(comparisonOperatorWithCallee(functionDecl( - functionDecl(DurationConversionFunction()) + functionDecl(durationConversionFunction()) .bind("function_decl")))) .bind("binop"); @@ -38,9 +38,9 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) { // if nothing needs to be done. if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS())) return; - std::string LhsReplacement = + const std::string LhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS()); - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS()); diag(Binop->getBeginLoc(), "perform comparison in the duration domain") diff --git a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp index cf591d9..ef06a9e 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp @@ -19,7 +19,7 @@ namespace clang::tidy::abseil { void DurationConversionCastCheck::registerMatchers(MatchFinder *Finder) { auto CallMatcher = ignoringImpCasts(callExpr( - callee(functionDecl(DurationConversionFunction()).bind("func_decl")), + callee(functionDecl(durationConversionFunction()).bind("func_decl")), hasArgument(0, expr().bind("arg")))); Finder->addMatcher( @@ -41,7 +41,7 @@ void DurationConversionCastCheck::check( const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl"); const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg"); - StringRef ConversionFuncName = FuncDecl->getName(); + const StringRef ConversionFuncName = FuncDecl->getName(); std::optional<DurationScale> Scale = getScaleForDurationInverse(ConversionFuncName); @@ -51,7 +51,8 @@ void DurationConversionCastCheck::check( // Casting a double to an integer. if (MatchedCast->getTypeAsWritten()->isIntegerType() && ConversionFuncName.contains("Double")) { - llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).second; + const llvm::StringRef NewFuncName = + getDurationInverseForScale(*Scale).second; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to an integer rather than " @@ -66,7 +67,8 @@ void DurationConversionCastCheck::check( // Casting an integer to a double. if (MatchedCast->getTypeAsWritten()->isRealFloatingType() && ConversionFuncName.contains("Int64")) { - llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).first; + const llvm::StringRef NewFuncName = + getDurationInverseForScale(*Scale).first; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to " "a floating-point number rather than " diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp index cccd7cf..83906fe 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp @@ -28,7 +28,7 @@ static bool insideMacroDefinition(const MatchFinder::MatchResult &Result, void DurationFactoryFloatCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( - callExpr(callee(functionDecl(DurationFactoryFunction())), + callExpr(callee(functionDecl(durationFactoryFunction())), hasArgument(0, anyOf(cxxStaticCastExpr(hasDestinationType( realFloatingPointType())), cStyleCastExpr(hasDestinationType( diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp index 1d6ff1a..9e403fb8 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp @@ -112,7 +112,7 @@ static std::optional<DurationScale> getNewScale(DurationScale OldScale, void DurationFactoryScaleCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr( - callee(functionDecl(DurationFactoryFunction()).bind("call_decl")), + callee(functionDecl(durationFactoryFunction()).bind("call_decl")), hasArgument( 0, ignoringImpCasts(anyOf( @@ -158,7 +158,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { if (!MaybeScale) return; - DurationScale Scale = *MaybeScale; + const DurationScale Scale = *MaybeScale; const Expr *Remainder = nullptr; std::optional<DurationScale> NewScale; diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp index ee19796..a78d07d 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp @@ -20,7 +20,7 @@ namespace clang::tidy::abseil { /// Returns an integer if the fractional part of a `FloatingLiteral` is `0`. static std::optional<llvm::APSInt> truncateIfIntegral(const FloatingLiteral &FloatLiteral) { - double Value = FloatLiteral.getValueAsApproximateDouble(); + const double Value = FloatLiteral.getValueAsApproximateDouble(); if (std::fmod(Value, 1) == 0) { if (Value >= static_cast<double>(1U << 31)) return std::nullopt; @@ -69,7 +69,7 @@ rewriteInverseDurationCall(const MatchFinder::MatchResult &Result, static std::optional<std::string> rewriteInverseTimeCall(const MatchFinder::MatchResult &Result, DurationScale Scale, const Expr &Node) { - llvm::StringRef InverseFunction = getTimeInverseForScale(Scale); + const llvm::StringRef InverseFunction = getTimeInverseForScale(Scale); if (const auto *MaybeCallArg = selectFirst<const Expr>( "e", match(callExpr(callee(functionDecl(hasName(InverseFunction))), hasArgument(0, expr().bind("e"))), diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h index 27d6ca0..e3b1753 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h +++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h @@ -96,7 +96,7 @@ bool isInMacro(const ast_matchers::MatchFinder::MatchResult &Result, const Expr *E); AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, - DurationConversionFunction) { + durationConversionFunction) { using namespace clang::ast_matchers; return functionDecl( hasAnyName("::absl::ToDoubleHours", "::absl::ToDoubleMinutes", @@ -108,7 +108,7 @@ AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, } AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, - DurationFactoryFunction) { + durationFactoryFunction) { using namespace clang::ast_matchers; return functionDecl(hasAnyName("::absl::Nanoseconds", "::absl::Microseconds", "::absl::Milliseconds", "::absl::Seconds", @@ -116,7 +116,7 @@ AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, } AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, - TimeConversionFunction) { + timeConversionFunction) { using namespace clang::ast_matchers; return functionDecl(hasAnyName( "::absl::ToUnixHours", "::absl::ToUnixMinutes", "::absl::ToUnixSeconds", @@ -125,12 +125,12 @@ AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, AST_MATCHER_FUNCTION_P(ast_matchers::internal::Matcher<Stmt>, comparisonOperatorWithCallee, - ast_matchers::internal::Matcher<Decl>, funcDecl) { + ast_matchers::internal::Matcher<Decl>, FuncDecl) { using namespace clang::ast_matchers; return binaryOperator( anyOf(hasOperatorName(">"), hasOperatorName(">="), hasOperatorName("=="), hasOperatorName("<="), hasOperatorName("<")), - hasEitherOperand(ignoringImpCasts(callExpr(callee(funcDecl))))); + hasEitherOperand(ignoringImpCasts(callExpr(callee(FuncDecl))))); } } // namespace clang::tidy::abseil diff --git a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp index fd5e203..42a7df4 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp @@ -21,7 +21,7 @@ void DurationSubtractionCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( binaryOperator( hasOperatorName("-"), - hasLHS(callExpr(callee(functionDecl(DurationConversionFunction()) + hasLHS(callExpr(callee(functionDecl(durationConversionFunction()) .bind("function_decl")), hasArgument(0, expr().bind("lhs_arg"))))) .bind("binop"), @@ -41,7 +41,7 @@ void DurationSubtractionCheck::check(const MatchFinder::MatchResult &Result) { if (!Scale) return; - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS()); const Expr *LhsArg = Result.Nodes.getNodeAs<Expr>("lhs_arg"); diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp index 805d7da..5867fb6 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp @@ -19,10 +19,10 @@ namespace clang::tidy::abseil { void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) { for (const auto &Scale : {"Hours", "Minutes", "Seconds", "Milliseconds", "Microseconds", "Nanoseconds"}) { - std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str(); - std::string FloatConversion = + const std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str(); + const std::string FloatConversion = (llvm::Twine("::absl::ToDouble") + Scale).str(); - std::string IntegerConversion = + const std::string IntegerConversion = (llvm::Twine("::absl::ToInt64") + Scale).str(); // Matcher which matches the current scale's factory with a `1` argument, diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h index 59af8968..f5d2511 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H #include "../ClangTidyCheck.h" @@ -31,4 +31,4 @@ public: } // namespace clang::tidy::abseil -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H diff --git a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp index d9f6551..0827526 100644 --- a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp @@ -29,7 +29,7 @@ makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) { assert(Literal->getCharByteWidth() == 1 && "StrSplit doesn't support wide char"); std::string Result = clang::tooling::fixit::getText(*Literal, Context).str(); - bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")"); + const bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")"); // Since raw string literal might contain unescaped non-printable characters, // we normalize them using `StringLiteral::outputString`. if (IsRawStringLiteral) { diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp index c090e5a..5f4cb66 100644 --- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp @@ -32,7 +32,7 @@ void NoInternalDependenciesCheck::check( const auto *InternalDependency = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep"); - SourceLocation LocAtFault = + const SourceLocation LocAtFault = Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc()); if (!LocAtFault.isValid()) diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h index 2911a1a..2291831 100644 --- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H #include "../ClangTidyCheck.h" @@ -31,4 +31,4 @@ public: } // namespace clang::tidy::abseil -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp index 92d6305..e1063c4f 100644 --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -92,7 +92,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) { const auto *FindFun = Result.Nodes.getNodeAs<CXXMethodDecl>("findfun"); assert(FindFun != nullptr); - bool Rev = FindFun->getName().contains("rfind"); + const bool Rev = FindFun->getName().contains("rfind"); if (ComparisonExpr->getBeginLoc().isMacroID()) return; @@ -107,7 +107,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) { Context.getLangOpts()); // Create the StartsWith string, negating if comparison was "!=". - bool Neg = ComparisonExpr->getOpcode() == BO_NE; + const bool Neg = ComparisonExpr->getOpcode() == BO_NE; // Create the warning message and a FixIt hint replacing the original expr. auto Diagnostic = diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp index 52121a5..5d80b16 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp @@ -18,7 +18,7 @@ namespace clang::tidy::abseil { void TimeComparisonCheck::registerMatchers(MatchFinder *Finder) { auto Matcher = expr(comparisonOperatorWithCallee(functionDecl( - functionDecl(TimeConversionFunction()).bind("function_decl")))) + functionDecl(timeConversionFunction()).bind("function_decl")))) .bind("binop"); Finder->addMatcher(Matcher, this); @@ -39,9 +39,9 @@ void TimeComparisonCheck::check(const MatchFinder::MatchResult &Result) { // want to handle the case of rewriting both sides. This is much simpler if // we unconditionally try and rewrite both, and let the rewriter determine // if nothing needs to be done. - std::string LhsReplacement = + const std::string LhsReplacement = rewriteExprFromNumberToTime(Result, *Scale, Binop->getLHS()); - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToTime(Result, *Scale, Binop->getRHS()); diag(Binop->getBeginLoc(), "perform comparison in the time domain") diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h index 703d951..74a877a 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H #include "../ClangTidyCheck.h" @@ -31,4 +31,4 @@ public: } // namespace clang::tidy::abseil -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp index 228d974..4ae49d2 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp @@ -93,7 +93,7 @@ void TimeSubtractionCheck::emitDiagnostic(const Expr *Node, void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { for (const char *ScaleName : {"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) { - std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); + const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); std::optional<DurationScale> Scale = getScaleForTimeInverse(TimeInverse); assert(Scale && "Unknown scale encountered"); @@ -127,7 +127,7 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binop"); - std::string InverseName = + const std::string InverseName = Result.Nodes.getNodeAs<FunctionDecl>("func_decl")->getNameAsString(); if (insideMacroDefinition(Result, BinOp->getSourceRange())) return; @@ -144,7 +144,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { // We're working with the first case of matcher, and need to replace the // entire 'Duration' factory call. (Which also means being careful about // our order-of-operations and optionally putting in some parenthesis. - bool NeedParens = parensRequired(Result, OuterCall); + const bool NeedParens = parensRequired(Result, OuterCall); emitDiagnostic( OuterCall, @@ -169,7 +169,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { // converts it from the inverse to a Duration. In this case, we replace // the outer with just the subtraction expression, which gives the right // type and scale, taking care again about parenthesis. - bool NeedParens = parensRequired(Result, MaybeCallArg); + const bool NeedParens = parensRequired(Result, MaybeCallArg); emitDiagnostic( MaybeCallArg, diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp index f7905e0..1a6ff30 100644 --- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp @@ -104,7 +104,7 @@ void UpgradeDurationConversionsCheck::registerMatchers(MatchFinder *Finder) { hasCastKind(CK_UserDefinedConversion)))), hasParent(callExpr( callee(functionDecl( - DurationFactoryFunction(), + durationFactoryFunction(), unless(hasParent(functionTemplateDecl())))), hasArgument(0, expr().bind("arg"))))) .bind("OuterExpr")), @@ -117,10 +117,10 @@ void UpgradeDurationConversionsCheck::check( "implicit conversion to 'int64_t' is deprecated in this context; use an " "explicit cast instead"; - TraversalKindScope RAII(*Result.Context, TK_AsIs); + const TraversalKindScope RAII(*Result.Context, TK_AsIs); const auto *ArgExpr = Result.Nodes.getNodeAs<Expr>("arg"); - SourceLocation Loc = ArgExpr->getBeginLoc(); + const SourceLocation Loc = ArgExpr->getBeginLoc(); const auto *OuterExpr = Result.Nodes.getNodeAs<Expr>("OuterExpr"); @@ -139,13 +139,13 @@ void UpgradeDurationConversionsCheck::check( // We gather source locations from template matches not in template // instantiations for future matches. - internal::Matcher<Stmt> IsInsideTemplate = + const internal::Matcher<Stmt> IsInsideTemplate = hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl()))); if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty()) MatchedTemplateLocations.insert(Loc); - DiagnosticBuilder Diag = diag(Loc, Message); - CharSourceRange SourceRange = Lexer::makeFileCharRange( + const DiagnosticBuilder Diag = diag(Loc, Message); + const CharSourceRange SourceRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(ArgExpr->getSourceRange()), *Result.SourceManager, Result.Context->getLangOpts()); if (SourceRange.isInvalid()) |
