From ab2d3ce47d6fead7fb79b3c0c7c4c6ac2b930d45 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Fri, 29 Jan 2021 00:49:53 +0100 Subject: [PATCH] [clang-tidy] Applied clang-tidy fixes. NFC Applied fixes enabled by the LLVM's .clang-tidy configs. Reverted files where fixes introduced compile errors: clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp $ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -fix clang-tools-extra/clang-tidy/ Enabled checks: llvm-else-after-return llvm-header-guard llvm-include-order llvm-namespace-comment llvm-prefer-isa-or-dyn-cast-in-conditionals llvm-prefer-register-over-unsigned llvm-qualified-auto llvm-twine-local misc-definitions-in-headers misc-misplaced-const misc-new-delete-overloads misc-no-recursion misc-non-copyable-objects misc-redundant-expression misc-static-assert misc-throw-by-value-catch-by-reference misc-unconventional-assign-operator misc-uniqueptr-reset-release misc-unused-alias-decls misc-unused-using-decls readability-identifier-naming Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D95614 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 6 +-- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp | 2 +- .../clang-tidy/ExpandModularHeadersPPCallbacks.cpp | 2 +- clang-tools-extra/clang-tidy/GlobList.cpp | 8 ++-- .../clang-tidy/abseil/DurationDivisionCheck.cpp | 12 +++--- .../abseil/DurationFactoryFloatCheck.cpp | 4 +- .../abseil/DurationFactoryScaleCheck.cpp | 26 +++++------ .../clang-tidy/abseil/DurationRewriter.cpp | 4 +- .../abseil/DurationUnnecessaryConversionCheck.cpp | 20 ++++----- .../clang-tidy/abseil/NoNamespaceCheck.cpp | 4 +- .../abseil/RedundantStrcatCallsCheck.cpp | 21 +++++---- .../abseil/StringFindStrContainsCheck.cpp | 4 +- .../clang-tidy/abseil/TimeSubtractionCheck.cpp | 10 ++--- .../altera/KernelNameRestrictionCheck.cpp | 8 ++-- .../clang-tidy/android/AndroidTidyModule.cpp | 2 +- .../clang-tidy/bugprone/ArgumentCommentCheck.cpp | 2 +- .../bugprone/BadSignalToKillThreadCheck.cpp | 4 +- .../clang-tidy/bugprone/BranchCloneCheck.cpp | 26 +++++------ .../bugprone/CopyConstructorInitCheck.cpp | 4 +- .../bugprone/ForwardingReferenceOverloadCheck.cpp | 8 ++-- .../bugprone/IncorrectRoundingsCheck.cpp | 6 +-- .../clang-tidy/bugprone/InfiniteLoopCheck.cpp | 2 +- .../bugprone/LambdaFunctionNameCheck.cpp | 10 ++--- .../bugprone/NotNullTerminatedResultCheck.cpp | 18 ++++---- .../bugprone/ReservedIdentifierCheck.cpp | 4 +- .../clang-tidy/bugprone/SizeofExpressionCheck.cpp | 6 ++- .../bugprone/SpuriouslyWakeUpFunctionsCheck.cpp | 34 +++++++-------- .../bugprone/StringLiteralWithEmbeddedNulCheck.cpp | 4 +- .../bugprone/SuspiciousEnumUsageCheck.cpp | 16 +++---- .../bugprone/SuspiciousMissingCommaCheck.cpp | 4 +- .../bugprone/TerminatingContinueCheck.cpp | 4 +- .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 10 ++--- .../clang-tidy/cert/LimitedRandomnessCheck.cpp | 6 +-- .../clang-tidy/cert/StrToNumCheck.cpp | 22 +++++----- .../clang-tidy/concurrency/MtUnsafeCheck.cpp | 4 +- .../cppcoreguidelines/MacroUsageCheck.cpp | 4 +- .../NarrowingConversionsCheck.cpp | 8 ++-- .../cppcoreguidelines/ProTypeCstyleCastCheck.cpp | 6 +-- .../cppcoreguidelines/ProTypeMemberInitCheck.cpp | 8 ++-- .../cppcoreguidelines/ProTypeVarargCheck.cpp | 4 +- .../SpecialMemberFunctionsCheck.cpp | 20 ++++----- .../fuchsia/MultipleInheritanceCheck.cpp | 8 ++-- .../clang-tidy/google/AvoidCStyleCastsCheck.cpp | 4 +- .../AvoidUnderscoreInGoogletestNameCheck.cpp | 4 +- .../clang-tidy/google/ExplicitConstructorCheck.cpp | 14 +++--- .../clang-tidy/google/FunctionNamingCheck.cpp | 4 +- .../clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp | 5 +-- .../clang-tidy/misc/NoRecursionCheck.cpp | 10 ++--- .../clang-tidy/misc/RedundantExpressionCheck.cpp | 25 ++++++----- .../clang-tidy/misc/UnusedParametersCheck.cpp | 6 +-- .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 4 +- .../modernize/DeprecatedIosBaseAliasesCheck.cpp | 2 +- .../clang-tidy/modernize/LoopConvertCheck.cpp | 34 ++++++++------- .../clang-tidy/modernize/LoopConvertUtils.cpp | 8 ++-- .../clang-tidy/modernize/MakeSmartPtrCheck.cpp | 31 ++++++-------- .../clang-tidy/modernize/RedundantVoidArgCheck.cpp | 4 +- .../modernize/ReplaceRandomShuffleCheck.cpp | 15 +++---- .../clang-tidy/modernize/UseAutoCheck.cpp | 4 +- .../clang-tidy/modernize/UseEqualsDefaultCheck.cpp | 2 +- .../clang-tidy/modernize/UseNullptrCheck.cpp | 4 +- .../clang-tidy/modernize/UseOverrideCheck.cpp | 12 +++--- .../modernize/UseTrailingReturnTypeCheck.cpp | 20 ++++----- .../clang-tidy/modernize/UseUsingCheck.cpp | 12 +++--- .../clang-tidy/mpi/BufferDerefCheck.cpp | 20 ++++----- .../clang-tidy/mpi/TypeMismatchCheck.cpp | 40 ++++++++--------- .../clang-tidy/objc/ForbiddenSubclassingCheck.cpp | 2 +- .../clang-tidy/objc/PropertyDeclarationCheck.cpp | 2 +- .../performance/FasterStringFindCheck.cpp | 16 +++---- .../performance/ImplicitConversionInLoopCheck.cpp | 6 +-- .../InefficientStringConcatenationCheck.cpp | 2 +- .../InefficientVectorOperationCheck.cpp | 4 +- .../clang-tidy/performance/MoveConstArgCheck.cpp | 6 +-- .../performance/TypePromotionInMathFnCheck.cpp | 50 +++++++++++----------- .../performance/UnnecessaryCopyInitialization.cpp | 10 ++--- .../clang-tidy/plugin/ClangTidyPlugin.cpp | 5 +-- .../clang-tidy/portability/SIMDIntrinsicsCheck.cpp | 8 ++-- .../readability/AvoidConstParamsInDecls.cpp | 10 ++--- .../readability/BracesAroundStatementsCheck.cpp | 11 ++--- .../FunctionCognitiveComplexityCheck.cpp | 16 +++---- .../readability/IdentifierNamingCheck.cpp | 9 ++-- .../readability/ImplicitBoolConversionCheck.cpp | 37 ++++++++-------- .../readability/MakeMemberFunctionConstCheck.cpp | 14 +++--- .../readability/MisleadingIndentationCheck.cpp | 14 +++--- .../clang-tidy/readability/NamedParameterCheck.cpp | 2 +- .../readability/RedundantControlFlowCheck.cpp | 8 ++-- .../readability/RedundantDeclarationCheck.cpp | 2 +- .../readability/RedundantPreprocessorCheck.cpp | 12 +++--- .../readability/RedundantStringInitCheck.cpp | 10 ++--- .../readability/SimplifyBooleanExprCheck.cpp | 22 +++++----- .../readability/SimplifySubscriptExprCheck.cpp | 4 +- .../readability/UppercaseLiteralSuffixCheck.cpp | 10 ++--- .../clang-tidy/readability/UseAnyOfAllOfCheck.cpp | 18 ++++---- clang-tools-extra/clang-tidy/utils/ASTUtils.cpp | 10 ++--- .../clang-tidy/utils/ExceptionAnalyzer.cpp | 4 +- .../clang-tidy/utils/ExprSequence.cpp | 2 +- .../clang-tidy/utils/IncludeSorter.cpp | 37 ++++++++-------- 96 files changed, 513 insertions(+), 519 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 12d2134..dc523d0 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -67,7 +67,7 @@ public: AnalyzerDiagnosticConsumer(ClangTidyContext &Context) : Context(Context) {} void FlushDiagnosticsImpl(std::vector &Diags, - FilesMade *filesMade) override { + FilesMade *FilesMade) override { for (const ento::PathDiagnostic *PD : Diags) { SmallString<64> CheckName(AnalyzerCheckNamePrefix); CheckName += PD->getCheckerName(); @@ -186,7 +186,7 @@ public: reportNote(Note); } - void Finish() { + void finish() { if (ApplyFixes && TotalFixes > 0) { Rewriter Rewrite(SourceMgr, LangOpts); for (const auto &FileAndReplacements : FileReplacements) { @@ -596,7 +596,7 @@ void handleErrors(llvm::ArrayRef Errors, // Return to the initial directory to correctly resolve next Error. FileSystem.setCurrentWorkingDirectory(InitialWorkingDir.get()); } - Reporter.Finish(); + Reporter.finish(); WarningsAsErrorsCount += Reporter.getWarningsAsErrorsCount(); } diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp index be068aa..1e62d1c 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp @@ -47,7 +47,7 @@ template <> struct MappingTraits { IO.mapRequired("name", File.Name); IO.mapOptional("lines", File.LineRanges); } - static std::string validate(IO &io, FileFilter &File) { + static std::string validate(IO &Io, FileFilter &File) { if (File.Name.empty()) return "No file name specified"; for (const FileFilter::LineRange &Range : File.LineRanges) { diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index 1d008c2..12795f0 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -125,7 +125,7 @@ void ExpandModularHeadersPPCallbacks::handleModuleFile( Recorder->addNecessaryFile(IF.getFile()); }); // Recursively handle all transitively imported modules. - for (auto Import : MF->Imports) + for (auto *Import : MF->Imports) handleModuleFile(Import); } diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp index 5b70b8d..43945fc 100644 --- a/clang-tools-extra/clang-tidy/GlobList.cpp +++ b/clang-tools-extra/clang-tidy/GlobList.cpp @@ -14,7 +14,7 @@ using namespace tidy; // Returns true if GlobList starts with the negative indicator ('-'), removes it // from the GlobList. -static bool ConsumeNegativeIndicator(StringRef &GlobList) { +static bool consumeNegativeIndicator(StringRef &GlobList) { GlobList = GlobList.trim(" \r\n"); if (GlobList.startswith("-")) { GlobList = GlobList.substr(1); @@ -25,7 +25,7 @@ static bool ConsumeNegativeIndicator(StringRef &GlobList) { // Converts first glob from the comma-separated list of globs to Regex and // removes it and the trailing comma from the GlobList. -static llvm::Regex ConsumeGlob(StringRef &GlobList) { +static llvm::Regex consumeGlob(StringRef &GlobList) { StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(',')); StringRef Glob = UntrimmedGlob.trim(' '); GlobList = GlobList.substr(UntrimmedGlob.size() + 1); @@ -46,8 +46,8 @@ GlobList::GlobList(StringRef Globs) { Items.reserve(Globs.count(',') + 1); do { GlobListItem Item; - Item.IsPositive = !ConsumeNegativeIndicator(Globs); - Item.Regex = ConsumeGlob(Globs); + Item.IsPositive = !consumeNegativeIndicator(Globs); + Item.Regex = consumeGlob(Globs); Items.push_back(std::move(Item)); } while (!Globs.empty()); } diff --git a/clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp index 5ded02a..0fb750c 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp @@ -17,10 +17,10 @@ namespace abseil { using namespace clang::ast_matchers; -void DurationDivisionCheck::registerMatchers(MatchFinder *finder) { +void DurationDivisionCheck::registerMatchers(MatchFinder *Finder) { const auto DurationExpr = expr(hasType(cxxRecordDecl(hasName("::absl::Duration")))); - finder->addMatcher( + Finder->addMatcher( traverse(TK_AsIs, implicitCastExpr( hasSourceExpression(ignoringParenCasts( @@ -35,8 +35,8 @@ void DurationDivisionCheck::registerMatchers(MatchFinder *finder) { this); } -void DurationDivisionCheck::check(const MatchFinder::MatchResult &result) { - const auto *OpCall = result.Nodes.getNodeAs("OpCall"); +void DurationDivisionCheck::check(const MatchFinder::MatchResult &Result) { + const auto *OpCall = Result.Nodes.getNodeAs("OpCall"); diag(OpCall->getOperatorLoc(), "operator/ on absl::Duration objects performs integer division; " "did you mean to use FDivDuration()?") @@ -47,8 +47,8 @@ void DurationDivisionCheck::check(const MatchFinder::MatchResult &result) { ", ") << FixItHint::CreateInsertion( Lexer::getLocForEndOfToken( - result.SourceManager->getSpellingLoc(OpCall->getEndLoc()), 0, - *result.SourceManager, result.Context->getLangOpts()), + Result.SourceManager->getSpellingLoc(OpCall->getEndLoc()), 0, + *Result.SourceManager, Result.Context->getLangOpts()), ")"); } diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp index ed7e9fd..1f1dc07 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp @@ -20,7 +20,7 @@ namespace tidy { namespace abseil { // Returns `true` if `Range` is inside a macro definition. -static bool InsideMacroDefinition(const MatchFinder::MatchResult &Result, +static bool insideMacroDefinition(const MatchFinder::MatchResult &Result, SourceRange Range) { return !clang::Lexer::makeFileCharRange( clang::CharSourceRange::getCharRange(Range), @@ -46,7 +46,7 @@ void DurationFactoryFloatCheck::check(const MatchFinder::MatchResult &Result) { const auto *MatchedCall = Result.Nodes.getNodeAs("call"); // Don't try and replace things inside of macro definitions. - if (InsideMacroDefinition(Result, MatchedCall->getSourceRange())) + if (insideMacroDefinition(Result, MatchedCall->getSourceRange())) return; const Expr *Arg = MatchedCall->getArg(0)->IgnoreImpCasts(); diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp index 0e537fc..7da75fa 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp @@ -35,7 +35,7 @@ getScaleForFactory(llvm::StringRef FactoryName) { // Given either an integer or float literal, return its value. // One and only one of `IntLit` and `FloatLit` should be provided. -static double GetValue(const IntegerLiteral *IntLit, +static double getValue(const IntegerLiteral *IntLit, const FloatingLiteral *FloatLit) { if (IntLit) return IntLit->getValue().getLimitedValue(); @@ -48,7 +48,7 @@ static double GetValue(const IntegerLiteral *IntLit, // would produce a new scale. If so, return a tuple containing the new scale // and a suitable Multiplier for that scale, otherwise `None`. static llvm::Optional> -GetNewScaleSingleStep(DurationScale OldScale, double Multiplier) { +getNewScaleSingleStep(DurationScale OldScale, double Multiplier) { switch (OldScale) { case DurationScale::Hours: if (Multiplier <= 1.0 / 60.0) @@ -94,17 +94,17 @@ GetNewScaleSingleStep(DurationScale OldScale, double Multiplier) { // Given the scale of a duration and a `Multiplier`, determine if `Multiplier` // would produce a new scale. If so, return it, otherwise `None`. -static llvm::Optional GetNewScale(DurationScale OldScale, +static llvm::Optional getNewScale(DurationScale OldScale, double Multiplier) { while (Multiplier != 1.0) { - llvm::Optional> result = - GetNewScaleSingleStep(OldScale, Multiplier); - if (!result) + llvm::Optional> Result = + getNewScaleSingleStep(OldScale, Multiplier); + if (!Result) break; - if (std::get<1>(*result) == 1.0) - return std::get<0>(*result); - Multiplier = std::get<1>(*result); - OldScale = std::get<0>(*result); + if (std::get<1>(*Result) == 1.0) + return std::get<0>(*Result); + Multiplier = std::get<1>(*Result); + OldScale = std::get<0>(*Result); } return llvm::None; @@ -173,7 +173,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { const auto *IntLit = llvm::dyn_cast(MultBinOp->getLHS()); const auto *FloatLit = llvm::dyn_cast(MultBinOp->getLHS()); if (IntLit || FloatLit) { - NewScale = GetNewScale(Scale, GetValue(IntLit, FloatLit)); + NewScale = getNewScale(Scale, getValue(IntLit, FloatLit)); if (NewScale) Remainder = MultBinOp->getRHS(); } @@ -183,7 +183,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { IntLit = llvm::dyn_cast(MultBinOp->getRHS()); FloatLit = llvm::dyn_cast(MultBinOp->getRHS()); if (IntLit || FloatLit) { - NewScale = GetNewScale(Scale, GetValue(IntLit, FloatLit)); + NewScale = getNewScale(Scale, getValue(IntLit, FloatLit)); if (NewScale) Remainder = MultBinOp->getLHS(); } @@ -195,7 +195,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { const auto *FloatLit = llvm::dyn_cast(DivBinOp->getRHS()); llvm::Optional NewScale = - GetNewScale(Scale, 1.0 / FloatLit->getValueAsApproximateDouble()); + getNewScale(Scale, 1.0 / FloatLit->getValueAsApproximateDouble()); if (NewScale) { const Expr *Remainder = DivBinOp->getLHS(); diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp index 39ee86b..125812f 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp @@ -138,8 +138,8 @@ llvm::StringRef getTimeFactoryForScale(DurationScale Scale) { } /// Returns the Time factory function name for a given `Scale`. -llvm::StringRef getTimeInverseForScale(DurationScale scale) { - switch (scale) { +llvm::StringRef getTimeInverseForScale(DurationScale Scale) { + switch (Scale) { case DurationScale::Hours: return "absl::ToUnixHours"; case DurationScale::Minutes: diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp index 28f970e..b357d80 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp @@ -30,31 +30,31 @@ void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) { // Matcher which matches the current scale's factory with a `1` argument, // e.g. `absl::Seconds(1)`. - auto factory_matcher = ignoringElidableConstructorCall( + auto FactoryMatcher = ignoringElidableConstructorCall( callExpr(callee(functionDecl(hasName(DurationFactory))), hasArgument(0, ignoringImpCasts(integerLiteral(equals(1)))))); // Matcher which matches either inverse function and binds its argument, // e.g. `absl::ToDoubleSeconds(dur)`. - auto inverse_function_matcher = callExpr( + auto InverseFunctionMatcher = callExpr( callee(functionDecl(hasAnyName(FloatConversion, IntegerConversion))), hasArgument(0, expr().bind("arg"))); // Matcher which matches a duration divided by the factory_matcher above, // e.g. `dur / absl::Seconds(1)`. - auto division_operator_matcher = cxxOperatorCallExpr( + auto DivisionOperatorMatcher = cxxOperatorCallExpr( hasOverloadedOperatorName("/"), hasArgument(0, expr().bind("arg")), - hasArgument(1, factory_matcher)); + hasArgument(1, FactoryMatcher)); // Matcher which matches a duration argument to `FDivDuration`, // e.g. `absl::FDivDuration(dur, absl::Seconds(1))` - auto fdiv_matcher = callExpr( + auto FdivMatcher = callExpr( callee(functionDecl(hasName("::absl::FDivDuration"))), - hasArgument(0, expr().bind("arg")), hasArgument(1, factory_matcher)); + hasArgument(0, expr().bind("arg")), hasArgument(1, FactoryMatcher)); // Matcher which matches a duration argument being scaled, // e.g. `absl::ToDoubleSeconds(dur) * 2` - auto scalar_matcher = ignoringImpCasts( + auto ScalarMatcher = ignoringImpCasts( binaryOperator(hasOperatorName("*"), hasEitherOperand(expr(ignoringParenImpCasts( callExpr(callee(functionDecl(hasAnyName( @@ -65,9 +65,9 @@ void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(callee(functionDecl(hasName(DurationFactory))), - hasArgument(0, anyOf(inverse_function_matcher, - division_operator_matcher, fdiv_matcher, - scalar_matcher))) + hasArgument(0, anyOf(InverseFunctionMatcher, + DivisionOperatorMatcher, FdivMatcher, + ScalarMatcher))) .bind("call"), this); } diff --git a/clang-tools-extra/clang-tidy/abseil/NoNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/abseil/NoNamespaceCheck.cpp index 3f93d4a..4e7b093 100644 --- a/clang-tools-extra/clang-tidy/abseil/NoNamespaceCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/NoNamespaceCheck.cpp @@ -25,10 +25,10 @@ void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) { } void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) { - const auto *abslNamespaceDecl = + const auto *AbslNamespaceDecl = Result.Nodes.getNodeAs("abslNamespace"); - diag(abslNamespaceDecl->getLocation(), + diag(AbslNamespaceDecl->getLocation(), "namespace 'absl' is reserved for implementation of the Abseil library " "and should not be opened in user code"); } diff --git a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp index abcf570..15171be 100644 --- a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp @@ -46,7 +46,7 @@ struct StrCatCheckResult { std::vector Hints; }; -void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) { +void removeCallLeaveArgs(const CallExpr *Call, StrCatCheckResult *CheckResult) { if (Call->getNumArgs() == 0) return; // Remove 'Foo(' @@ -59,9 +59,9 @@ void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) { Call->getRParenLoc(), Call->getEndLoc().getLocWithOffset(1)))); } -const clang::CallExpr* ProcessArgument(const Expr* Arg, - const MatchFinder::MatchResult& Result, - StrCatCheckResult* CheckResult) { +const clang::CallExpr *processArgument(const Expr *Arg, + const MatchFinder::MatchResult &Result, + StrCatCheckResult *CheckResult) { const auto IsAlphanum = hasDeclaration(cxxMethodDecl(hasName("AlphaNum"))); static const auto* const Strcat = new auto(hasName("::absl::StrCat")); const auto IsStrcat = cxxBindTemporaryExpr( @@ -73,14 +73,14 @@ const clang::CallExpr* ProcessArgument(const Expr* Arg, hasArgument(0, IsStrcat)), IsStrcat))), *Arg->IgnoreParenImpCasts(), *Result.Context))) { - RemoveCallLeaveArgs(SubStrcatCall, CheckResult); + removeCallLeaveArgs(SubStrcatCall, CheckResult); return SubStrcatCall; } return nullptr; } -StrCatCheckResult ProcessCall(const CallExpr* RootCall, bool IsAppend, - const MatchFinder::MatchResult& Result) { +StrCatCheckResult processCall(const CallExpr *RootCall, bool IsAppend, + const MatchFinder::MatchResult &Result) { StrCatCheckResult CheckResult; std::deque CallsToProcess = {RootCall}; @@ -94,8 +94,8 @@ StrCatCheckResult ProcessCall(const CallExpr* RootCall, bool IsAppend, for (const auto *Arg : CallExpr->arguments()) { if (StartArg-- > 0) continue; - if (const clang::CallExpr* Sub = - ProcessArgument(Arg, Result, &CheckResult)) { + if (const clang::CallExpr *Sub = + processArgument(Arg, Result, &CheckResult)) { CallsToProcess.push_back(Sub); } } @@ -123,8 +123,7 @@ void RedundantStrcatCallsCheck::check(const MatchFinder::MatchResult& Result) { return; } - const StrCatCheckResult CheckResult = - ProcessCall(RootCall, IsAppend, Result); + const StrCatCheckResult CheckResult = processCall(RootCall, IsAppend, Result); if (CheckResult.NumCalls == 1) { // Just one call, so nothing to fix. return; diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp index 3054689..f4a519c 100644 --- a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp @@ -62,7 +62,7 @@ makeRewriteRule(const std::vector &StringLikeClassNames, hasArgument(1, cxxDefaultArgExpr())), onImplicitObjectArgument(expr().bind("string_being_searched"))); - RewriteRule rule = applyFirst( + RewriteRule Rule = applyFirst( {makeRule( binaryOperator(hasOperatorName("=="), hasOperands(ignoringParenImpCasts(StringNpos), @@ -80,7 +80,7 @@ makeRewriteRule(const std::vector &StringLikeClassNames, addInclude(AbseilStringsMatchHeader)}, cat("use absl::StrContains instead " "of find() != npos"))}); - return rule; + return Rule; } StringFindStrContainsCheck::StringFindStrContainsCheck( diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp index 9231971..58ce1f4 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp @@ -20,7 +20,7 @@ namespace tidy { namespace abseil { // Returns `true` if `Range` is inside a macro definition. -static bool InsideMacroDefinition(const MatchFinder::MatchResult &Result, +static bool insideMacroDefinition(const MatchFinder::MatchResult &Result, SourceRange Range) { return !clang::Lexer::makeFileCharRange( clang::CharSourceRange::getCharRange(Range), @@ -93,7 +93,7 @@ void TimeSubtractionCheck::emitDiagnostic(const Expr *Node, } void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { - for (auto ScaleName : + for (const char *ScaleName : {"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) { std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); llvm::Optional Scale = getScaleForTimeInverse(TimeInverse); @@ -131,7 +131,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { const auto *BinOp = Result.Nodes.getNodeAs("binop"); std::string InverseName = Result.Nodes.getNodeAs("func_decl")->getNameAsString(); - if (InsideMacroDefinition(Result, BinOp->getSourceRange())) + if (insideMacroDefinition(Result, BinOp->getSourceRange())) return; llvm::Optional Scale = getScaleForTimeInverse(InverseName); @@ -140,7 +140,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { const auto *OuterCall = Result.Nodes.getNodeAs("outer_call"); if (OuterCall) { - if (InsideMacroDefinition(Result, OuterCall->getSourceRange())) + if (insideMacroDefinition(Result, OuterCall->getSourceRange())) return; // We're working with the first case of matcher, and need to replace the @@ -166,7 +166,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { .bind("arg"))), *BinOp, *Result.Context)); if (MaybeCallArg && MaybeCallArg->getArg(0)->IgnoreImpCasts() == BinOp && - !InsideMacroDefinition(Result, MaybeCallArg->getSourceRange())) { + !insideMacroDefinition(Result, MaybeCallArg->getSourceRange())) { // Handle the case where the matched expression is inside a call which // converts it from the inverse to a Duration. In this case, we replace // the outer with just the subtraction expression, which gives the right diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp index eb49977..f7c71cc 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -39,7 +39,7 @@ public: private: /// Returns true if the name of the file with path FilePath is 'kernel.cl', /// 'verilog.cl', or 'vhdl.cl'. The file name check is case insensitive. - bool FileNameIsRestricted(StringRef FilePath); + bool fileNameIsRestricted(StringRef FilePath); struct IncludeDirective { SourceLocation Loc; // Location in the include directive. @@ -68,7 +68,7 @@ void KernelNameRestrictionPPCallbacks::InclusionDirective( IncludeDirectives.push_back(std::move(ID)); } -bool KernelNameRestrictionPPCallbacks::FileNameIsRestricted( +bool KernelNameRestrictionPPCallbacks::fileNameIsRestricted( StringRef FileName) { return FileName.equals_lower("kernel.cl") || FileName.equals_lower("verilog.cl") || @@ -80,7 +80,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() { // Check main file for restricted names. const FileEntry *Entry = SM.getFileEntryForID(SM.getMainFileID()); StringRef FileName = llvm::sys::path::filename(Entry->getName()); - if (FileNameIsRestricted(FileName)) + if (fileNameIsRestricted(FileName)) Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()), "compiling '%0' may cause additional compilation errors due " "to the name of the kernel source file; consider renaming the " @@ -93,7 +93,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() { // Check included files for restricted names. for (const IncludeDirective &ID : IncludeDirectives) { StringRef FileName = llvm::sys::path::filename(ID.FileName); - if (FileNameIsRestricted(FileName)) + if (fileNameIsRestricted(FileName)) Check.diag(ID.Loc, "including '%0' may cause additional compilation errors due " "to the name of the kernel source file; consider renaming the " diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp index e978309..b24c0d9 100644 --- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp @@ -20,8 +20,8 @@ #include "CloexecInotifyInitCheck.h" #include "CloexecMemfdCreateCheck.h" #include "CloexecOpenCheck.h" -#include "CloexecPipeCheck.h" #include "CloexecPipe2Check.h" +#include "CloexecPipeCheck.h" #include "CloexecSocketCheck.h" #include "ComparisonInTempFailureRetryCheck.h" diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp index 3e401da..32af0ee 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -280,7 +280,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx, IdentifierInfo *II = PVD->getIdentifier(); if (!II) continue; - if (auto Template = Callee->getTemplateInstantiationPattern()) { + if (FunctionDecl *Template = Callee->getTemplateInstantiationPattern()) { // Don't warn on arguments for parameters instantiated from template // parameter packs. If we find more arguments than the template // definition has, it also means that they correspond to a parameter diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp index 3833640..cef7fd5 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp @@ -65,8 +65,8 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) { } void BadSignalToKillThreadCheck::registerPPCallbacks( - const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) { - PP = pp; + const SourceManager &SM, Preprocessor *Pp, Preprocessor *ModuleExpanderPP) { + PP = Pp; } } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp index 8c89350..9b44951 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp @@ -41,12 +41,12 @@ static bool areSwitchBranchesIdentical(const SwitchBranch LHS, if (LHS.size() != RHS.size()) return false; - for (size_t i = 0, Size = LHS.size(); i < Size; i++) { + for (size_t I = 0, Size = LHS.size(); I < Size; I++) { // NOTE: We strip goto labels and annotations in addition to stripping // the `case X:` or `default:` labels, but it is very unlikely that this // would casue false positives in real-world code. - if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(), - RHS[i]->stripLabelLikeStatements(), Context)) { + if (!areStatementsIdentical(LHS[I]->stripLabelLikeStatements(), + RHS[I]->stripLabelLikeStatements(), Context)) { return false; } } @@ -114,35 +114,35 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) { size_t N = Branches.size(); llvm::BitVector KnownAsClone(N); - for (size_t i = 0; i + 1 < N; i++) { + for (size_t I = 0; I + 1 < N; I++) { // We have already seen Branches[i] as a clone of an earlier branch. - if (KnownAsClone[i]) + if (KnownAsClone[I]) continue; int NumCopies = 1; - for (size_t j = i + 1; j < N; j++) { - if (KnownAsClone[j] || - !areStatementsIdentical(Branches[i]->IgnoreContainers(), - Branches[j]->IgnoreContainers(), Context)) + for (size_t J = I + 1; J < N; J++) { + if (KnownAsClone[J] || + !areStatementsIdentical(Branches[I]->IgnoreContainers(), + Branches[J]->IgnoreContainers(), Context)) continue; NumCopies++; - KnownAsClone[j] = true; + KnownAsClone[J] = true; if (NumCopies == 2) { // We report the first occurrence only when we find the second one. - diag(Branches[i]->getBeginLoc(), + diag(Branches[I]->getBeginLoc(), "repeated branch in conditional chain"); SourceLocation End = - Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0, + Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0, *Result.SourceManager, getLangOpts()); if (End.isValid()) { diag(End, "end of the original", DiagnosticIDs::Note); } } - diag(Branches[j]->getBeginLoc(), "clone %0 starts here", + diag(Branches[J]->getBeginLoc(), "clone %0 starts here", DiagnosticIDs::Note) << (NumCopies - 1); } diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp index 1a4d454..5f0cbe0 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp @@ -110,8 +110,8 @@ void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) { FixItMsg += ' '; Diag << FixItHint::CreateInsertion(FixItLoc, FixItMsg); -} // namespace misc +} -} // namespace misc +} // namespace bugprone } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp index 20b6203..aeb3db9 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp @@ -41,9 +41,9 @@ AST_MATCHER(QualType, isEnableIf) { } if (!BaseType) return false; - if (CheckTemplate(BaseType->getAs())) { + if (CheckTemplate(BaseType->getAs())) return true; // Case: enable_if_t< >. - } else if (const auto *Elaborated = BaseType->getAs()) { + if (const auto *Elaborated = BaseType->getAs()) { if (const auto *Qualifier = Elaborated->getQualifier()->getAsType()) { if (CheckTemplate(Qualifier->getAs())) { return true; // Case: enable_if< >::type. @@ -68,7 +68,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) { unless(references(isConstQualified()))))) .bind("parm-var"); - DeclarationMatcher findOverload = + DeclarationMatcher FindOverload = cxxConstructorDecl( hasParameter(0, ForwardingRefParm), unless(hasAnyParameter( @@ -78,7 +78,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) { // No warning: enable_if as type parameter. hasDefaultArgument(isEnableIf()))))))) .bind("ctor"); - Finder->addMatcher(findOverload, this); + Finder->addMatcher(FindOverload, this); } void ForwardingReferenceOverloadCheck::check( diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp index 5002107..2f908e4 100644 --- a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp @@ -21,11 +21,11 @@ namespace bugprone { namespace { AST_MATCHER(FloatingLiteral, floatHalf) { - const auto &literal = Node.getValue(); + const auto &Literal = Node.getValue(); if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle()) - return literal.convertToFloat() == 0.5f; + return Literal.convertToFloat() == 0.5f; if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble()) - return literal.convertToDouble() == 0.5; + return Literal.convertToDouble() == 0.5; return false; } } // namespace diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp index 310fbec..bf1b510 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "InfiniteLoopCheck.h" +#include "../utils/Aliasing.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h" -#include "../utils/Aliasing.h" using namespace clang::ast_matchers; using clang::tidy::utils::hasPtrOrReferenceInFunc; diff --git a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp index 2b7edc1..ba6f6ba 100644 --- a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp @@ -35,19 +35,19 @@ public: void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override { - bool has_file = false; - bool has_line = false; + bool HasFile = false; + bool HasLine = false; for (const auto& T : MD.getMacroInfo()->tokens()) { if (T.is(tok::identifier)) { StringRef IdentName = T.getIdentifierInfo()->getName(); if (IdentName == "__FILE__") { - has_file = true; + HasFile = true; } else if (IdentName == "__LINE__") { - has_line = true; + HasLine = true; } } } - if (has_file && has_line) { + if (HasFile && HasLine) { SuppressMacroExpansions->insert(Range); } } diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp index 9a44ba2..36d83b2 100644 --- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp @@ -232,7 +232,7 @@ isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) { return true; if (const auto *LengthExpr = Result.Nodes.getNodeAs(LengthExprName)) - if (dyn_cast(LengthExpr->IgnoreParenImpCasts())) + if (isa(LengthExpr->IgnoreParenImpCasts())) return false; // Check the strlen()'s argument's 'VarDecl' is equal to the source 'VarDecl'. @@ -508,8 +508,8 @@ void NotNullTerminatedResultCheck::storeOptions( } void NotNullTerminatedResultCheck::registerPPCallbacks( - const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) { - PP = pp; + const SourceManager &SM, Preprocessor *Pp, Preprocessor *ModuleExpanderPP) { + PP = Pp; } namespace { @@ -750,7 +750,7 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) { auto Memcpy = Match({"memcpy", 0, 1, 2, false}); // errno_t memcpy_s(void *dest, size_t ds, const void *src, size_t count) - auto Memcpy_s = Match({"memcpy_s", 0, 2, 3, false}); + auto MemcpyS = Match({"memcpy_s", 0, 2, 3, false}); // void *memchr(const void *src, int c, size_t count) auto Memchr = Match({"memchr", None, 0, 2, false}); @@ -759,7 +759,7 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) { auto Memmove = Match({"memmove", 0, 1, 2, false}); // errno_t memmove_s(void *dest, size_t ds, const void *src, size_t count) - auto Memmove_s = Match({"memmove_s", 0, 2, 3, false}); + auto MemmoveS = Match({"memmove_s", 0, 2, 3, false}); // int strncmp(const char *str1, const char *str2, size_t count); auto StrncmpRHS = Match({"strncmp", None, 1, 2, true}); @@ -769,10 +769,10 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) { auto Strxfrm = Match({"strxfrm", 0, 1, 2, false}); // errno_t strerror_s(char *buffer, size_t bufferSize, int errnum); - auto Strerror_s = Match({"strerror_s", 0, None, 1, false}); + auto StrerrorS = Match({"strerror_s", 0, None, 1, false}); - auto AnyOfMatchers = anyOf(Memcpy, Memcpy_s, Memmove, Memmove_s, StrncmpRHS, - StrncmpLHS, Strxfrm, Strerror_s); + auto AnyOfMatchers = anyOf(Memcpy, MemcpyS, Memmove, MemmoveS, StrncmpRHS, + StrncmpLHS, Strxfrm, StrerrorS); Finder->addMatcher(callExpr(AnyOfMatchers).bind(FunctionExprName), this); @@ -920,7 +920,7 @@ void NotNullTerminatedResultCheck::memcpy_sFix( void NotNullTerminatedResultCheck::memchrFix( StringRef Name, const MatchFinder::MatchResult &Result) { const auto *FunctionExpr = Result.Nodes.getNodeAs(FunctionExprName); - if (const auto GivenCL = dyn_cast(FunctionExpr->getArg(1))) + if (const auto *GivenCL = dyn_cast(FunctionExpr->getArg(1))) if (GivenCL->getValue() != 0) return; diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp index 47a84c2..df2968e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp @@ -172,8 +172,8 @@ ReservedIdentifierCheck::GetMacroFailureInfo(const Token &MacroNameTok, RenamerClangTidyCheck::DiagInfo ReservedIdentifierCheck::GetDiagInfo(const NamingCheckId &ID, const NamingCheckFailure &Failure) const { - return DiagInfo{Message, [&](DiagnosticBuilder &diag) { - diag << ID.second + return DiagInfo{Message, [&](DiagnosticBuilder &Diag) { + Diag << ID.second << getMessageSelectIndex(Failure.Info.KindName); }}; } diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index 5790e8f..1123c7c 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp @@ -35,10 +35,12 @@ AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth, if (const auto *CE = dyn_cast(E)) { const auto M = hasSizeOfDescendant(Depth - 1, InnerMatcher); return M.matches(*CE->getSubExpr(), Finder, Builder); - } else if (const auto *UE = dyn_cast(E)) { + } + if (const auto *UE = dyn_cast(E)) { const auto M = hasSizeOfDescendant(Depth - 1, InnerMatcher); return M.matches(*UE->getSubExpr(), Finder, Builder); - } else if (const auto *BE = dyn_cast(E)) { + } + if (const auto *BE = dyn_cast(E)) { const auto LHS = hasSizeOfDescendant(Depth - 1, InnerMatcher); const auto RHS = hasSizeOfDescendant(Depth - 1, InnerMatcher); return LHS.matches(*BE->getLHS(), Finder, Builder) || diff --git a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp index ee46818..1a9bea6 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp @@ -18,14 +18,14 @@ namespace bugprone { void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) { - auto hasUniqueLock = hasDescendant(declRefExpr( + auto HasUniqueLock = hasDescendant(declRefExpr( hasDeclaration(varDecl(hasType(recordDecl(classTemplateSpecializationDecl( hasName("::std::unique_lock"), hasTemplateArgument( 0, templateArgument(refersToType(qualType(hasDeclaration( cxxRecordDecl(hasName("::std::mutex")))))))))))))); - auto hasWaitDescendantCPP = hasDescendant( + auto HasWaitDescendantCpp = hasDescendant( cxxMemberCallExpr( anyOf( allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl( @@ -34,51 +34,49 @@ void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) { onImplicitObjectArgument( declRefExpr(to(varDecl(hasType(references(recordDecl( hasName("::std::condition_variable")))))))), - hasUniqueLock), + HasUniqueLock), allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl( allOf(hasName("::std::condition_variable::wait_for"), parameterCountIs(2)))))), onImplicitObjectArgument( declRefExpr(to(varDecl(hasType(references(recordDecl( hasName("::std::condition_variable")))))))), - hasUniqueLock), + HasUniqueLock), allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl( allOf(hasName("::std::condition_variable::wait_until"), parameterCountIs(2)))))), onImplicitObjectArgument( declRefExpr(to(varDecl(hasType(references(recordDecl( hasName("::std::condition_variable")))))))), - hasUniqueLock) + HasUniqueLock) )) .bind("wait")); - auto hasWaitDescendantC = hasDescendant( + auto HasWaitDescendantC = hasDescendant( callExpr(callee(functionDecl(hasAnyName("cnd_wait", "cnd_timedwait")))) .bind("wait")); if (getLangOpts().CPlusPlus) { // Check for `CON54-CPP` Finder->addMatcher( ifStmt( - - allOf(hasWaitDescendantCPP, - unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantCPP)), - hasDescendant(whileStmt(hasWaitDescendantCPP)), - hasDescendant(forStmt(hasWaitDescendantCPP)), - hasDescendant(doStmt(hasWaitDescendantCPP))))) + allOf(HasWaitDescendantCpp, + unless(anyOf(hasDescendant(ifStmt(HasWaitDescendantCpp)), + hasDescendant(whileStmt(HasWaitDescendantCpp)), + hasDescendant(forStmt(HasWaitDescendantCpp)), + hasDescendant(doStmt(HasWaitDescendantCpp))))) ), this); } else { // Check for `CON36-C` Finder->addMatcher( - ifStmt( - allOf(hasWaitDescendantC, - unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantC)), - hasDescendant(whileStmt(hasWaitDescendantC)), - hasDescendant(forStmt(hasWaitDescendantC)), - hasDescendant(doStmt(hasWaitDescendantC)), + allOf(HasWaitDescendantC, + unless(anyOf(hasDescendant(ifStmt(HasWaitDescendantC)), + hasDescendant(whileStmt(HasWaitDescendantC)), + hasDescendant(forStmt(HasWaitDescendantC)), + hasDescendant(doStmt(HasWaitDescendantC)), hasParent(whileStmt()), hasParent(compoundStmt(hasParent(whileStmt()))), hasParent(forStmt()), diff --git a/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp index b533db7..080d4ab 100644 --- a/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp @@ -18,8 +18,8 @@ namespace bugprone { namespace { AST_MATCHER(StringLiteral, containsNul) { - for (size_t i = 0; i < Node.getLength(); ++i) - if (Node.getCodeUnit(i) == '\0') + for (size_t I = 0; I < Node.getLength(); ++I) + if (Node.getCodeUnit(I) == '\0') return true; return false; } diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp index cc59601..3faa28c 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp @@ -117,14 +117,14 @@ void SuspiciousEnumUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { } void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) { - const auto enumExpr = [](StringRef RefName, StringRef DeclName) { + const auto EnumExpr = [](StringRef RefName, StringRef DeclName) { return expr(ignoringImpCasts(expr().bind(RefName)), ignoringImpCasts(hasType(enumDecl().bind(DeclName)))); }; Finder->addMatcher( - binaryOperator(hasOperatorName("|"), hasLHS(enumExpr("", "enumDecl")), - hasRHS(expr(enumExpr("", "otherEnumDecl"), + binaryOperator(hasOperatorName("|"), hasLHS(EnumExpr("", "enumDecl")), + hasRHS(expr(EnumExpr("", "otherEnumDecl"), ignoringImpCasts(hasType(enumDecl( unless(equalsBoundNode("enumDecl")))))))) .bind("diffEnumOp"), @@ -132,8 +132,8 @@ void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( binaryOperator(hasAnyOperatorName("+", "|"), - hasLHS(enumExpr("lhsExpr", "enumDecl")), - hasRHS(expr(enumExpr("rhsExpr", ""), + hasLHS(EnumExpr("lhsExpr", "enumDecl")), + hasRHS(expr(EnumExpr("rhsExpr", ""), ignoringImpCasts(hasType( enumDecl(equalsBoundNode("enumDecl"))))))), this); @@ -141,12 +141,12 @@ void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( binaryOperator( hasAnyOperatorName("+", "|"), - hasOperands(expr(hasType(isInteger()), unless(enumExpr("", ""))), - enumExpr("enumExpr", "enumDecl"))), + hasOperands(expr(hasType(isInteger()), unless(EnumExpr("", ""))), + EnumExpr("enumExpr", "enumDecl"))), this); Finder->addMatcher(binaryOperator(hasAnyOperatorName("|=", "+="), - hasRHS(enumExpr("enumExpr", "enumDecl"))), + hasRHS(EnumExpr("enumExpr", "enumDecl"))), this); } diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp index 8fd1abe..092809e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp @@ -108,8 +108,8 @@ void SuspiciousMissingCommaCheck::check( // Count the number of occurrence of concatenated string literal. unsigned int Count = 0; - for (unsigned int i = 0; i < Size; ++i) { - const Expr *Child = InitializerList->getInit(i)->IgnoreImpCasts(); + for (unsigned int I = 0; I < Size; ++I) { + const Expr *Child = InitializerList->getInit(I)->IgnoreImpCasts(); if (const auto *Literal = dyn_cast(Child)) { if (Literal->getNumConcatenated() > 1) ++Count; diff --git a/clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp index beeeb2c..43402a2 100644 --- a/clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp @@ -19,7 +19,7 @@ namespace tidy { namespace bugprone { void TerminatingContinueCheck::registerMatchers(MatchFinder *Finder) { - const auto doWithFalse = + const auto DoWithFalse = doStmt(hasCondition(ignoringImpCasts( anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)), cxxNullPtrLiteralExpr(), gnuNullExpr()))), @@ -29,7 +29,7 @@ void TerminatingContinueCheck::registerMatchers(MatchFinder *Finder) { continueStmt(hasAncestor(stmt(anyOf(forStmt(), whileStmt(), cxxForRangeStmt(), doStmt())) .bind("closestLoop")), - hasAncestor(doWithFalse)) + hasAncestor(DoWithFalse)) .bind("continue"), this); } diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index 9d08dbe..6c8a974 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -256,7 +256,7 @@ void UseAfterMoveFinder::getDeclRefs( if (!S) continue; - auto addDeclRefs = [this, Block, + auto AddDeclRefs = [this, Block, DeclRefs](const ArrayRef Matches) { for (const auto &Match : Matches) { const auto *DeclRef = Match.getNodeAs("declref"); @@ -275,9 +275,9 @@ void UseAfterMoveFinder::getDeclRefs( unless(inDecltypeOrTemplateArg())) .bind("declref"); - addDeclRefs(match(traverse(TK_AsIs, findAll(DeclRefMatcher)), *S->getStmt(), + AddDeclRefs(match(traverse(TK_AsIs, findAll(DeclRefMatcher)), *S->getStmt(), *Context)); - addDeclRefs(match(findAll(cxxOperatorCallExpr( + AddDeclRefs(match(findAll(cxxOperatorCallExpr( hasAnyOverloadedOperatorName("*", "->", "[]"), hasArgument(0, DeclRefMatcher)) .bind("operator")), @@ -448,9 +448,9 @@ void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) { if (!Arg->getDecl()->getDeclContext()->isFunctionOrMethod()) return; - UseAfterMoveFinder finder(Result.Context); + UseAfterMoveFinder Finder(Result.Context); UseAfterMove Use; - if (finder.find(FunctionBody, MovingCall, Arg->getDecl(), &Use)) + if (Finder.find(FunctionBody, MovingCall, Arg->getDecl(), &Use)) emitDiagnostic(MovingCall, Arg, Use, this, Result.Context); } diff --git a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp b/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp index 847f05e..9733a4e 100644 --- a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp @@ -24,12 +24,12 @@ void LimitedRandomnessCheck::registerMatchers(MatchFinder *Finder) { } void LimitedRandomnessCheck::check(const MatchFinder::MatchResult &Result) { - std::string msg = ""; + std::string Msg = ""; if (getLangOpts().CPlusPlus) - msg = "; use C++11 random library instead"; + Msg = "; use C++11 random library instead"; const auto *MatchedDecl = Result.Nodes.getNodeAs("randomGenerator"); - diag(MatchedDecl->getBeginLoc(), "rand() has limited randomness" + msg); + diag(MatchedDecl->getBeginLoc(), "rand() has limited randomness" + Msg); } } // namespace cert diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp b/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp index 9d26060..c7abbe1 100644 --- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp +++ b/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp @@ -8,8 +8,8 @@ #include "StrToNumCheck.h" #include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/AST/FormatString.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" #include "llvm/ADT/StringSwitch.h" #include @@ -48,7 +48,7 @@ enum class ConversionKind { ToLongDouble }; -ConversionKind ClassifyConversionFunc(const FunctionDecl *FD) { +ConversionKind classifyConversionFunc(const FunctionDecl *FD) { return llvm::StringSwitch(FD->getName()) .Cases("atoi", "atol", ConversionKind::ToInt) .Case("atoll", ConversionKind::ToLongInt) @@ -56,7 +56,7 @@ ConversionKind ClassifyConversionFunc(const FunctionDecl *FD) { .Default(ConversionKind::None); } -ConversionKind ClassifyFormatString(StringRef Fmt, const LangOptions &LO, +ConversionKind classifyFormatString(StringRef Fmt, const LangOptions &LO, const TargetInfo &TI) { // Scan the format string for the first problematic format specifier, then // report that as the conversion type. This will miss additional conversion @@ -66,8 +66,8 @@ ConversionKind ClassifyFormatString(StringRef Fmt, const LangOptions &LO, ConversionKind CK; bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS, - const char *startSpecifier, - unsigned specifierLen) override { + const char *StartSpecifier, + unsigned SpecifierLen) override { // If we just consume the argument without assignment, we don't care // about it having conversion errors. if (!FS.consumesDataArgument()) @@ -130,7 +130,7 @@ ConversionKind ClassifyFormatString(StringRef Fmt, const LangOptions &LO, return H.get(); } -StringRef ClassifyConversionType(ConversionKind K) { +StringRef classifyConversionType(ConversionKind K) { switch (K) { case ConversionKind::None: llvm_unreachable("Unexpected conversion kind"); @@ -150,7 +150,7 @@ StringRef ClassifyConversionType(ConversionKind K) { llvm_unreachable("Unknown conversion kind"); } -StringRef ClassifyReplacement(ConversionKind K) { +StringRef classifyReplacement(ConversionKind K) { switch (K) { case ConversionKind::None: llvm_unreachable("Unexpected conversion kind"); @@ -186,7 +186,7 @@ void StrToNumCheck::check(const MatchFinder::MatchResult &Result) { Result.Nodes.getNodeAs("converter")) { // Converter functions are always incorrect to use. FuncDecl = ConverterFunc; - Conversion = ClassifyConversionFunc(ConverterFunc); + Conversion = classifyConversionFunc(ConverterFunc); } else if (const auto *FFD = Result.Nodes.getNodeAs("formatted")) { StringRef FmtStr; @@ -213,7 +213,7 @@ void StrToNumCheck::check(const MatchFinder::MatchResult &Result) { // Formatted input functions need further checking of the format string to // determine whether a problematic conversion may be happening. - Conversion = ClassifyFormatString(FmtStr, getLangOpts(), + Conversion = classifyFormatString(FmtStr, getLangOpts(), Result.Context->getTargetInfo()); if (Conversion != ConversionKind::None) FuncDecl = FFD; @@ -225,8 +225,8 @@ void StrToNumCheck::check(const MatchFinder::MatchResult &Result) { diag(Call->getExprLoc(), "%0 used to convert a string to %1, but function will not report " "conversion errors; consider using '%2' instead") - << FuncDecl << ClassifyConversionType(Conversion) - << ClassifyReplacement(Conversion); + << FuncDecl << classifyConversionType(Conversion) + << classifyReplacement(Conversion); } } // namespace cert diff --git a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp index bc9f740..57c2c9c 100644 --- a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp +++ b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp @@ -277,8 +277,8 @@ template <> struct OptionEnumMapping { namespace concurrency { static ast_matchers::internal::Matcher -hasAnyMtUnsafeNames(MtUnsafeCheck::FunctionSet libc) { - switch (libc) { +hasAnyMtUnsafeNames(MtUnsafeCheck::FunctionSet Libc) { + switch (Libc) { case MtUnsafeCheck::FunctionSet::Posix: return hasAnyName(PosixFunctions); case MtUnsafeCheck::FunctionSet::Glibc: diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp index eb21bb4..4f56df0 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp @@ -22,8 +22,8 @@ namespace cppcoreguidelines { namespace { bool isCapsOnly(StringRef Name) { - return std::all_of(Name.begin(), Name.end(), [](const char c) { - if (std::isupper(c) || std::isdigit(c) || c == '_') + return std::all_of(Name.begin(), Name.end(), [](const char C) { + if (std::isupper(C) || std::isdigit(C) || C == '_') return true; return false; }); diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp index 6819d6a..86371fd 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp @@ -111,12 +111,12 @@ static bool getFloatingConstantExprValue(const ASTContext &Context, namespace { struct IntegerRange { - bool Contains(const IntegerRange &From) const { + bool contains(const IntegerRange &From) const { return llvm::APSInt::compareValues(Lower, From.Lower) <= 0 && llvm::APSInt::compareValues(Upper, From.Upper) >= 0; } - bool Contains(const llvm::APSInt &Value) const { + bool contains(const llvm::APSInt &Value) const { return llvm::APSInt::compareValues(Lower, Value) <= 0 && llvm::APSInt::compareValues(Upper, Value) >= 0; } @@ -160,14 +160,14 @@ static bool isWideEnoughToHold(const ASTContext &Context, const BuiltinType &ToType) { IntegerRange FromIntegerRange = createFromType(Context, FromType); IntegerRange ToIntegerRange = createFromType(Context, ToType); - return ToIntegerRange.Contains(FromIntegerRange); + return ToIntegerRange.contains(FromIntegerRange); } static bool isWideEnoughToHold(const ASTContext &Context, const llvm::APSInt &IntegerConstant, const BuiltinType &ToType) { IntegerRange ToIntegerRange = createFromType(Context, ToType); - return ToIntegerRange.Contains(IntegerConstant); + return ToIntegerRange.contains(IntegerConstant); } static llvm::SmallString<64> getValueAsString(const llvm::APSInt &Value, diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp index 6873e23..f172097 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp @@ -66,7 +66,7 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) { MatchedCast->getRParenLoc().getLocWithOffset(-1)), *Result.SourceManager, getLangOpts()); - auto diag_builder = diag( + auto DiagBuilder = diag( MatchedCast->getBeginLoc(), "do not use C-style cast to downcast from a base to a derived class; " "use dynamic_cast instead"); @@ -76,14 +76,14 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) { std::string CastText = ("dynamic_cast<" + DestTypeString + ">").str(); if (!isa(SubExpr)) { CastText.push_back('('); - diag_builder << FixItHint::CreateInsertion( + DiagBuilder << FixItHint::CreateInsertion( Lexer::getLocForEndOfToken(SubExpr->getEndLoc(), 0, *Result.SourceManager, getLangOpts()), ")"); } auto ParenRange = CharSourceRange::getTokenRange( MatchedCast->getLParenLoc(), MatchedCast->getRParenLoc()); - diag_builder << FixItHint::CreateReplacement(ParenRange, CastText); + DiagBuilder << FixItHint::CreateReplacement(ParenRange, CastText); } else { diag( MatchedCast->getBeginLoc(), diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index 67856be..6b40e52 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -140,17 +140,17 @@ struct IntializerInsertion { assert(!Initializers.empty() && "No initializers to insert"); std::string Code; llvm::raw_string_ostream Stream(Code); - std::string joined = + std::string Joined = llvm::join(Initializers.begin(), Initializers.end(), "(), "); switch (Placement) { case InitializerPlacement::New: - Stream << " : " << joined << "()"; + Stream << " : " << Joined << "()"; break; case InitializerPlacement::Before: - Stream << " " << joined << "(),"; + Stream << " " << Joined << "(),"; break; case InitializerPlacement::After: - Stream << ", " << joined << "()"; + Stream << ", " << Joined << "()"; break; } return Stream.str(); diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp index f6aeb832..ec0e87a 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp @@ -17,7 +17,7 @@ namespace clang { namespace tidy { namespace cppcoreguidelines { -const internal::VariadicDynCastAllOfMatcher vAArgExpr; +const internal::VariadicDynCastAllOfMatcher VAArgExpr; static constexpr StringRef AllowedVariadics[] = { // clang-format off @@ -71,7 +71,7 @@ AST_MATCHER_P(AdjustedType, hasOriginalType, } // namespace void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(vAArgExpr().bind("va_use"), this); + Finder->addMatcher(VAArgExpr().bind("va_use"), this); Finder->addMatcher( callExpr(callee(functionDecl(isVariadic(), diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp index 9c16436..c4684d4 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp @@ -90,8 +90,8 @@ join(ArrayRef SMFS, Stream << toString(SMFS[0]); size_t LastIndex = SMFS.size() - 1; - for (size_t i = 1; i < LastIndex; ++i) { - Stream << ", " << toString(SMFS[i]); + for (size_t I = 1; I < LastIndex; ++I) { + Stream << ", " << toString(SMFS[I]); } if (LastIndex != 0) { Stream << AndOr << toString(SMFS[LastIndex]); @@ -107,11 +107,11 @@ void SpecialMemberFunctionsCheck::check( ClassDefId ID(MatchedDecl->getLocation(), std::string(MatchedDecl->getName())); - auto StoreMember = [this, &ID](SpecialMemberFunctionData data) { + auto StoreMember = [this, &ID](SpecialMemberFunctionData Data) { llvm::SmallVectorImpl &Members = ClassWithSpecialMembers[ID]; - if (!llvm::is_contained(Members, data)) - Members.push_back(std::move(data)); + if (!llvm::is_contained(Members, Data)) + Members.push_back(std::move(Data)); }; if (const auto *Dtor = Result.Nodes.getNodeAs("dtor")) { @@ -146,14 +146,14 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers( llvm::SmallVector MissingMembers; auto HasMember = [&](SpecialMemberFunctionKind Kind) { - return llvm::any_of(DefinedMembers, [Kind](const auto &data) { - return data.FunctionKind == Kind; + return llvm::any_of(DefinedMembers, [Kind](const auto &Data) { + return Data.FunctionKind == Kind; }); }; auto IsDeleted = [&](SpecialMemberFunctionKind Kind) { - return llvm::any_of(DefinedMembers, [Kind](const auto &data) { - return data.FunctionKind == Kind && data.IsDeleted; + return llvm::any_of(DefinedMembers, [Kind](const auto &Data) { + return Data.FunctionKind == Kind && Data.IsDeleted; }); }; @@ -197,7 +197,7 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers( if (!MissingMembers.empty()) { llvm::SmallVector DefinedMemberKinds; llvm::transform(DefinedMembers, std::back_inserter(DefinedMemberKinds), - [](const auto &data) { return data.FunctionKind; }); + [](const auto &Data) { return Data.FunctionKind; }); diag(ID.first, "class '%0' defines %1 but does not define %2") << ID.second << cppcoreguidelines::join(DefinedMemberKinds, " and ") << cppcoreguidelines::join(MissingMembers, " or "); diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp index 76b8ac0..ae3222a 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp @@ -28,23 +28,23 @@ AST_MATCHER(CXXRecordDecl, hasBases) { // Adds a node (by name) to the interface map, if it was not present in the map // previously. void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node, - bool isInterface) { + bool IsInterface) { assert(Node->getIdentifier()); StringRef Name = Node->getIdentifier()->getName(); - InterfaceMap.insert(std::make_pair(Name, isInterface)); + InterfaceMap.insert(std::make_pair(Name, IsInterface)); } // Returns "true" if the boolean "isInterface" has been set to the // interface status of the current Node. Return "false" if the // interface status for the current node is not yet known. bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node, - bool &isInterface) const { + bool &IsInterface) const { assert(Node->getIdentifier()); StringRef Name = Node->getIdentifier()->getName(); llvm::StringMapConstIterator Pair = InterfaceMap.find(Name); if (Pair == InterfaceMap.end()) return false; - isInterface = Pair->second; + IsInterface = Pair->second; return true; } diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp index 3125889..a32603d 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp @@ -67,7 +67,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) { if (CastExpr->getCastKind() == CK_ToVoid) return; - auto isFunction = [](QualType T) { + auto IsFunction = [](QualType T) { T = T.getCanonicalType().getNonReferenceType(); return T->isFunctionType() || T->isFunctionPointerType() || T->isMemberFunctionPointerType(); @@ -84,7 +84,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) { CastExpr->getLParenLoc(), CastExpr->getSubExprAsWritten()->getBeginLoc()); bool FnToFnCast = - isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten); + IsFunction(SourceTypeAsWritten) && IsFunction(DestTypeAsWritten); const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() && DestTypeAsWritten->isRecordType() && diff --git a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp index 3a5aaa1..783db8c 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp @@ -21,7 +21,7 @@ namespace tidy { namespace google { namespace readability { -constexpr llvm::StringLiteral kDisabledTestPrefix = "DISABLED_"; +constexpr llvm::StringLiteral KDisabledTestPrefix = "DISABLED_"; // Determines whether the macro is a Googletest test macro. static bool isGoogletestTestMacro(StringRef MacroName) { @@ -63,7 +63,7 @@ public: std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken); StringRef TestName = TestNameMaybeDisabled; - TestName.consume_front(kDisabledTestPrefix); + TestName.consume_front(KDisabledTestPrefix); if (TestName.contains('_')) Check->diag(TestNameToken->getLocation(), "avoid using \"_\" in test name \"%0\" according to " diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp index 80fc139..59f2dfb 100644 --- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp @@ -35,7 +35,7 @@ void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) { // Looks for the token matching the predicate and returns the range of the found // token including trailing whitespace. -static SourceRange FindToken(const SourceManager &Sources, +static SourceRange findToken(const SourceManager &Sources, const LangOptions &LangOpts, SourceLocation StartLoc, SourceLocation EndLoc, bool (*Pred)(const Token &)) { @@ -103,17 +103,17 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) { Ctor->getMinRequiredArguments() > 1) return; - bool takesInitializerList = isStdInitializerList( + bool TakesInitializerList = isStdInitializerList( Ctor->getParamDecl(0)->getType().getNonReferenceType()); if (Ctor->isExplicit() && - (Ctor->isCopyOrMoveConstructor() || takesInitializerList)) { - auto isKWExplicit = [](const Token &Tok) { + (Ctor->isCopyOrMoveConstructor() || TakesInitializerList)) { + auto IsKwExplicit = [](const Token &Tok) { return Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "explicit"; }; SourceRange ExplicitTokenRange = - FindToken(*Result.SourceManager, getLangOpts(), - Ctor->getOuterLocStart(), Ctor->getEndLoc(), isKWExplicit); + findToken(*Result.SourceManager, getLangOpts(), + Ctor->getOuterLocStart(), Ctor->getEndLoc(), IsKwExplicit); StringRef ConstructorDescription; if (Ctor->isMoveConstructor()) ConstructorDescription = "move"; @@ -133,7 +133,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) { } if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() || - takesInitializerList) + TakesInitializerList) return; bool SingleArgument = diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp index f29d650..cedc385 100644 --- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp @@ -60,8 +60,8 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) { size_t Index = 0; bool AtWordBoundary = true; while (Index < NewName.size()) { - char ch = NewName[Index]; - if (isalnum(ch)) { + char Ch = NewName[Index]; + if (isalnum(Ch)) { // Capitalize the first letter after every word boundary. if (AtWordBoundary) { NewName[Index] = toupper(NewName[Index]); diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp index 91e2cda..7feb0c7 100644 --- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp @@ -83,10 +83,9 @@ static std::size_t getNumberOfPossibleValues(QualType T, // and would not return 2 as result. if (T->isBooleanType()) return 2; - else if (T->isIntegralType(Context)) + if (T->isIntegralType(Context)) return twoPow(Context.getTypeSize(T)); - else - return 1; + return 1; } void MultiwayPathsCoveredCheck::check(const MatchFinder::MatchResult &Result) { diff --git a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp index 5b1dbf3..1200230 100644 --- a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp @@ -135,10 +135,10 @@ public: /// Insert a new element into the SmartSmallSetVector. /// \returns true if the element was inserted into the SmartSmallSetVector. bool insert(const T &X) { - bool result = setInsert(X); - if (result) + bool Result = setInsert(X); + if (Result) Vector.push_back(X); - return result; + return Result; } /// Clear the SmartSmallSetVector and return the underlying vector. @@ -157,7 +157,7 @@ using CallStackTy = // In given SCC, find *some* call stack that will be cyclic. // This will only find *one* such stack, it might not be the smallest one, // and there may be other loops. -CallStackTy PathfindSomeCycle(ArrayRef SCC) { +CallStackTy pathfindSomeCycle(ArrayRef SCC) { // We'll need to be able to performantly look up whether some CallGraphNode // is in SCC or not, so cache all the SCC elements in a set. const ImmutableSmallSet SCCElts(SCC); @@ -212,7 +212,7 @@ void NoRecursionCheck::handleSCC(ArrayRef SCC) { // the call graph. It doesn't *really* tell us about the cycles they form. // And there may be more than one cycle in SCC. // So let's form a call stack that eventually exposes *some* cycle. - const CallStackTy EventuallyCyclicCallStack = PathfindSomeCycle(SCC); + const CallStackTy EventuallyCyclicCallStack = pathfindSomeCycle(SCC); assert(!EventuallyCyclicCallStack.empty() && "We should've found the cycle"); // While last node of the call stack does cause a loop, due to the way we diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp index 9217c22..6a84360 100644 --- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp @@ -144,8 +144,7 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) { if (LeftUnaryExpr->isArgumentType() && RightUnaryExpr->isArgumentType()) return LeftUnaryExpr->getArgumentType() == RightUnaryExpr->getArgumentType(); - else if (!LeftUnaryExpr->isArgumentType() && - !RightUnaryExpr->isArgumentType()) + if (!LeftUnaryExpr->isArgumentType() && !RightUnaryExpr->isArgumentType()) return areEquivalentExpr(LeftUnaryExpr->getArgumentExpr(), RightUnaryExpr->getArgumentExpr()); @@ -166,11 +165,11 @@ static bool areEquivalentRanges(BinaryOperatorKind OpcodeLHS, return OpcodeLHS == OpcodeRHS; // Handle the case where constants are off by one: x <= 4 <==> x < 5. - APSInt ValueLHS_plus1; + APSInt ValueLhsPlus1; return ((OpcodeLHS == BO_LE && OpcodeRHS == BO_LT) || (OpcodeLHS == BO_GT && OpcodeRHS == BO_GE)) && - incrementWithoutOverflow(ValueLHS, ValueLHS_plus1) && - APSInt::compareValues(ValueLHS_plus1, ValueRHS) == 0; + incrementWithoutOverflow(ValueLHS, ValueLhsPlus1) && + APSInt::compareValues(ValueLhsPlus1, ValueRHS) == 0; } // For a given expression 'x', returns whether the ranges covered by the @@ -208,10 +207,10 @@ static bool areExclusiveRanges(BinaryOperatorKind OpcodeLHS, return true; // Handle the case where constants are off by one: x > 5 && x < 6. - APSInt ValueLHS_plus1; + APSInt ValueLhsPlus1; if (OpcodeLHS == BO_GT && OpcodeRHS == BO_LT && - incrementWithoutOverflow(ValueLHS, ValueLHS_plus1) && - APSInt::compareValues(ValueLHS_plus1, ValueRHS) == 0) + incrementWithoutOverflow(ValueLHS, ValueLhsPlus1) && + APSInt::compareValues(ValueLhsPlus1, ValueRHS) == 0) return true; return false; @@ -247,10 +246,10 @@ static bool rangesFullyCoverDomain(BinaryOperatorKind OpcodeLHS, } // Handle the case where constants are off by one: x <= 4 || x >= 5. - APSInt ValueLHS_plus1; + APSInt ValueLhsPlus1; if (OpcodeLHS == BO_LE && OpcodeRHS == BO_GE && - incrementWithoutOverflow(ValueLHS, ValueLHS_plus1) && - APSInt::compareValues(ValueLHS_plus1, ValueRHS) == 0) + incrementWithoutOverflow(ValueLHS, ValueLhsPlus1) && + APSInt::compareValues(ValueLhsPlus1, ValueRHS) == 0) return true; // Handle cases where the constants are different: x > 4 || x <= 7. @@ -623,7 +622,7 @@ static bool isNonConstReferenceType(QualType ParamType) { // controlled by the parameter `ParamsToCheckCount`. static bool canOverloadedOperatorArgsBeModified(const CXXOperatorCallExpr *OperatorCall, - bool checkSecondParam) { + bool CheckSecondParam) { const auto *OperatorDecl = dyn_cast_or_null(OperatorCall->getCalleeDecl()); // if we can't find the declaration, conservatively assume it can modify @@ -643,7 +642,7 @@ canOverloadedOperatorArgsBeModified(const CXXOperatorCallExpr *OperatorCall, if (isNonConstReferenceType(OperatorDecl->getParamDecl(0)->getType())) return true; - return checkSecondParam && ParamCount == 2 && + return CheckSecondParam && ParamCount == 2 && isNonConstReferenceType(OperatorDecl->getParamDecl(1)->getType()); } diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp index 535ac78..ee2ca87 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp @@ -177,8 +177,8 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Method = dyn_cast(Function)) if (Method->isLambdaStaticInvoker()) return; - for (unsigned i = 0, e = Function->getNumParams(); i != e; ++i) { - const auto *Param = Function->getParamDecl(i); + for (unsigned I = 0, E = Function->getNumParams(); I != E; ++I) { + const auto *Param = Function->getParamDecl(I); if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() || Param->hasAttr()) continue; @@ -190,7 +190,7 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) { Function->getBody()->child_end()) || (isa(Function) && cast(Function)->getNumCtorInitializers() > 0)) - warnOnUnusedParameter(Result, Function, i); + warnOnUnusedParameter(Result, Function, I); } } diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 96055c2..ca96ab6 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -50,7 +50,7 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl, // A function that helps to tell whether a TargetDecl in a UsingDecl will be // checked. Only variable, function, function template, class template, class, // enum declaration and enum constant declaration are considered. -static bool ShouldCheckDecl(const Decl *TargetDecl) { +static bool shouldCheckDecl(const Decl *TargetDecl) { return isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || @@ -105,7 +105,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { /*SkipTrailingWhitespaceAndNewLine=*/true)); for (const auto *UsingShadow : Using->shadows()) { const auto *TargetDecl = UsingShadow->getTargetDecl()->getCanonicalDecl(); - if (ShouldCheckDecl(TargetDecl)) + if (shouldCheckDecl(TargetDecl)) Context.UsingTargetDecls.insert(TargetDecl); } if (!Context.UsingTargetDecls.empty()) diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp index 2eef983..d621600 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp @@ -59,7 +59,7 @@ void DeprecatedIosBaseAliasesCheck::check( SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1); if (Replacement) { - auto FixName = *Replacement; + const char *FixName = *Replacement; auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use " "'std::ios_base::%1' instead") << TypeName << FixName; diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index 65384af..c017cac 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -71,20 +71,20 @@ static const char EndVarName[] = "endVar"; static const char DerefByValueResultName[] = "derefByValueResult"; static const char DerefByRefResultName[] = "derefByRefResult"; // shared matchers -static const TypeMatcher AnyType() { return anything(); } +static const TypeMatcher anyType() { return anything(); } -static const StatementMatcher IntegerComparisonMatcher() { +static const StatementMatcher integerComparisonMatcher() { return expr(ignoringParenImpCasts( declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName))))); } -static const DeclarationMatcher InitToZeroMatcher() { +static const DeclarationMatcher initToZeroMatcher() { return varDecl( hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0))))) .bind(InitVarName); } -static const StatementMatcher IncrementVarMatcher() { +static const StatementMatcher incrementVarMatcher() { return declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName))); } @@ -112,15 +112,16 @@ StatementMatcher makeArrayLoopMatcher() { return forStmt( unless(isInTemplateInstantiation()), - hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher()))), + hasLoopInit(declStmt(hasSingleDecl(initToZeroMatcher()))), hasCondition(anyOf( binaryOperator(hasOperatorName("<"), - hasLHS(IntegerComparisonMatcher()), + hasLHS(integerComparisonMatcher()), hasRHS(ArrayBoundMatcher)), binaryOperator(hasOperatorName(">"), hasLHS(ArrayBoundMatcher), - hasRHS(IntegerComparisonMatcher())))), - hasIncrement(unaryOperator(hasOperatorName("++"), - hasUnaryOperand(IncrementVarMatcher())))) + hasRHS(integerComparisonMatcher())))), + hasIncrement( + unaryOperator(hasOperatorName("++"), + hasUnaryOperand(incrementVarMatcher())))) .bind(LoopNameArray); } @@ -226,7 +227,7 @@ StatementMatcher makeIteratorLoopMatcher(bool IsReverse) { hasIncrement(anyOf( unaryOperator(hasOperatorName("++"), hasUnaryOperand(declRefExpr( - to(varDecl(hasType(pointsTo(AnyType()))) + to(varDecl(hasType(pointsTo(anyType()))) .bind(IncrementVarName))))), cxxOperatorCallExpr( hasOverloadedOperatorName("++"), @@ -313,17 +314,18 @@ StatementMatcher makePseudoArrayLoopMatcher() { unless(isInTemplateInstantiation()), hasLoopInit( anyOf(declStmt(declCountIs(2), - containsDeclaration(0, InitToZeroMatcher()), + containsDeclaration(0, initToZeroMatcher()), containsDeclaration(1, EndDeclMatcher)), - declStmt(hasSingleDecl(InitToZeroMatcher())))), + declStmt(hasSingleDecl(initToZeroMatcher())))), hasCondition(anyOf( binaryOperator(hasOperatorName("<"), - hasLHS(IntegerComparisonMatcher()), + hasLHS(integerComparisonMatcher()), hasRHS(IndexBoundMatcher)), binaryOperator(hasOperatorName(">"), hasLHS(IndexBoundMatcher), - hasRHS(IntegerComparisonMatcher())))), - hasIncrement(unaryOperator(hasOperatorName("++"), - hasUnaryOperand(IncrementVarMatcher())))) + hasRHS(integerComparisonMatcher())))), + hasIncrement( + unaryOperator(hasOperatorName("++"), + hasUnaryOperand(incrementVarMatcher())))) .bind(LoopNamePseudoArray); } diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index c20472c..74dd4a3 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -10,8 +10,8 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Lambda.h" -#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/APSInt.h" @@ -50,8 +50,8 @@ bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) { /// Scope, as we can map a VarDecl to its DeclStmt, then walk up the parent tree /// using StmtAncestors. bool StmtAncestorASTVisitor::VisitDeclStmt(DeclStmt *Decls) { - for (const auto *decl : Decls->decls()) { - if (const auto *V = dyn_cast(decl)) + for (const auto *Decl : Decls->decls()) { + if (const auto *V = dyn_cast(Decl)) DeclParents.insert(std::make_pair(V, Decls)); } return true; @@ -356,7 +356,7 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl, bool OnlyCasts = true; const Expr *Init = VDecl->getInit()->IgnoreParenImpCasts(); - if (Init && isa(Init)) { + if (isa_and_nonnull(Init)) { Init = digThroughConstructors(Init); OnlyCasts = false; } diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 4130140..54a5c5a 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -24,8 +24,7 @@ constexpr char ConstructorCall[] = "constructorCall"; constexpr char ResetCall[] = "resetCall"; constexpr char NewExpression[] = "newExpression"; -std::string GetNewExprName(const CXXNewExpr *NewExpr, - const SourceManager &SM, +std::string getNewExprName(const CXXNewExpr *NewExpr, const SourceManager &SM, const LangOptions &Lang) { StringRef WrittenName = Lexer::getSourceText( CharSourceRange::getTokenRange( @@ -183,8 +182,7 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, ASTContext *Ctx, // we have to add it back. ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size()); Diag << FixItHint::CreateInsertion( - ConstructCallEnd, - "<" + GetNewExprName(New, SM, getLangOpts()) + ">"); + ConstructCallEnd, "<" + getNewExprName(New, SM, getLangOpts()) + ">"); } else { ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle); } @@ -248,7 +246,7 @@ void MakeSmartPtrCheck::checkReset(SourceManager &SM, ASTContext *Ctx, Diag << FixItHint::CreateReplacement( CharSourceRange::getCharRange(OperatorLoc, ExprEnd), (llvm::Twine(" = ") + MakeSmartPtrFunctionName + "<" + - GetNewExprName(New, SM, getLangOpts()) + ">") + getNewExprName(New, SM, getLangOpts()) + ">") .str()); if (Expr->isArrow()) @@ -389,19 +387,18 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag, // std::make_smart_ptr(std::initializer_list({})); // std::make_smart_ptr(S{1, 2}, 3); return false; - } else { - // Direct initialization with ordinary constructors. - // struct S { S(int x); S(); }; - // smart_ptr(new S{5}); - // smart_ptr(new S{}); // use default constructor - // The arguments in the initialization list are going to be forwarded to - // the constructor, so this has to be replaced with: - // std::make_smart_ptr(5); - // std::make_smart_ptr(); - InitRange = SourceRange( - NewConstruct->getParenOrBraceRange().getBegin().getLocWithOffset(1), - NewConstruct->getParenOrBraceRange().getEnd().getLocWithOffset(-1)); } + // Direct initialization with ordinary constructors. + // struct S { S(int x); S(); }; + // smart_ptr(new S{5}); + // smart_ptr(new S{}); // use default constructor + // The arguments in the initialization list are going to be forwarded to + // the constructor, so this has to be replaced with: + // std::make_smart_ptr(5); + // std::make_smart_ptr(); + InitRange = SourceRange( + NewConstruct->getParenOrBraceRange().getBegin().getLocWithOffset(1), + NewConstruct->getParenOrBraceRange().getEnd().getLocWithOffset(-1)); } else { // Aggregate initialization. // smart_ptr(new Pair{first, second}); diff --git a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp index 7e44738..3214ae8 100644 --- a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp @@ -20,13 +20,13 @@ namespace { // Determine if the given QualType is a nullary function or pointer to same. bool protoTypeHasNoParms(QualType QT) { - if (auto PT = QT->getAs()) { + if (const auto *PT = QT->getAs()) { QT = PT->getPointeeType(); } if (auto *MPT = QT->getAs()) { QT = MPT->getPointeeType(); } - if (auto FP = QT->getAs()) { + if (const auto *FP = QT->getAs()) { return FP->getNumParams() == 0; } return false; diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp index f21482d..3cb934e 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp @@ -71,15 +71,14 @@ void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) { MatchedArgumentThree->getSourceRange(), "std::mt19937(std::random_device()())"); return DiagL; - } else { - auto DiagL = diag(MatchedCallExpr->getBeginLoc(), - "'std::random_shuffle' has been removed in C++17; use " - "'std::shuffle' instead"); - DiagL << FixItHint::CreateInsertion( - MatchedCallExpr->getRParenLoc(), - ", std::mt19937(std::random_device()())"); - return DiagL; } + auto DiagL = diag(MatchedCallExpr->getBeginLoc(), + "'std::random_shuffle' has been removed in C++17; use " + "'std::shuffle' instead"); + DiagL << FixItHint::CreateInsertion( + MatchedCallExpr->getRParenLoc(), + ", std::mt19937(std::random_device()())"); + return DiagL; }(); std::string NewName = "shuffle"; diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp index fab13cdb..a4a81ce 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp @@ -27,7 +27,7 @@ const char DeclWithNewId[] = "decl_new"; const char DeclWithCastId[] = "decl_cast"; const char DeclWithTemplateCastId[] = "decl_template"; -size_t GetTypeNameLength(bool RemoveStars, StringRef Text) { +size_t getTypeNameLength(bool RemoveStars, StringRef Text) { enum CharType { Space, Alpha, Punctuation }; CharType LastChar = Space, BeforeSpace = Punctuation; size_t NumChars = 0; @@ -399,7 +399,7 @@ void UseAutoCheck::replaceExpr( SourceRange Range(Loc.getSourceRange()); if (MinTypeNameLength != 0 && - GetTypeNameLength(RemoveStars, + getTypeNameLength(RemoveStars, tooling::fixit::getText(Loc.getSourceRange(), FirstDecl->getASTContext())) < MinTypeNameLength) diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp index d1d2582..9b91d18 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "UseEqualsDefaultCheck.h" +#include "../utils/LexerUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" -#include "../utils/LexerUtils.h" using namespace clang::ast_matchers; diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 25a789d..e32687b 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -173,9 +173,9 @@ private: class CastSequenceVisitor : public RecursiveASTVisitor { public: CastSequenceVisitor(ASTContext &Context, ArrayRef NullMacros, - ClangTidyCheck &check) + ClangTidyCheck &Check) : SM(Context.getSourceManager()), Context(Context), - NullMacros(NullMacros), Check(check), FirstSubExpr(nullptr), + NullMacros(NullMacros), Check(Check), FirstSubExpr(nullptr), PruneSubtree(false) {} bool TraverseStmt(Stmt *S) { diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp index bfce7a6..510e17f 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp @@ -43,7 +43,7 @@ void UseOverrideCheck::registerMatchers(MatchFinder *Finder) { // Re-lex the tokens to get precise locations to insert 'override' and remove // 'virtual'. static SmallVector -ParseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) { +parseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) { const SourceManager &Sources = *Result.SourceManager; std::pair LocInfo = Sources.getDecomposedLoc(Range.getBegin()); @@ -75,7 +75,7 @@ ParseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) { return Tokens; } -static StringRef GetText(const Token &Tok, const SourceManager &Sources) { +static StringRef getText(const Token &Tok, const SourceManager &Sources) { return StringRef(Sources.getCharacterData(Tok.getLocation()), Tok.getLength()); } @@ -136,7 +136,7 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { // FIXME: Instead of re-lexing and looking for specific macros such as // 'ABSTRACT', properly store the location of 'virtual' and '= 0' in each // FunctionDecl. - SmallVector Tokens = ParseTokens(FileRange, Result); + SmallVector Tokens = parseTokens(FileRange, Result); // Add 'override' on inline declarations that don't already have it. if (!HasFinal && !HasOverride) { @@ -185,15 +185,15 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { // location will point until after those markings. Therefore, the override // keyword shouldn't be inserted at the end, but before the '='. if (Tokens.size() > 2 && - (GetText(Tokens.back(), Sources) == "0" || + (getText(Tokens.back(), Sources) == "0" || Tokens.back().is(tok::kw_default) || Tokens.back().is(tok::kw_delete)) && - GetText(Tokens[Tokens.size() - 2], Sources) == "=") { + getText(Tokens[Tokens.size() - 2], Sources) == "=") { InsertLoc = Tokens[Tokens.size() - 2].getLocation(); // Check if we need to insert a space. if ((Tokens[Tokens.size() - 2].getFlags() & Token::LeadingSpace) == 0) ReplacementText = " " + OverrideSpelling + " "; - } else if (GetText(Tokens.back(), Sources) == "ABSTRACT") + } else if (getText(Tokens.back(), Sources) == "ABSTRACT") InsertLoc = Tokens.back().getLocation(); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp index bbb1e8c..b5c7227 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp @@ -31,7 +31,7 @@ public: bool shouldWalkTypesOfTypeLocs() const { return false; } - bool VisitUnqualName(StringRef UnqualName) { + bool visitUnqualName(StringRef UnqualName) { // Check for collisions with function arguments. for (ParmVarDecl *Param : F.parameters()) if (const IdentifierInfo *Ident = Param->getIdentifier()) @@ -49,17 +49,17 @@ public: if (!Elaborated) { switch (TL.getTypeLocClass()) { case TypeLoc::Record: - if (VisitUnqualName( + if (visitUnqualName( TL.getAs().getTypePtr()->getDecl()->getName())) return false; break; case TypeLoc::Enum: - if (VisitUnqualName( + if (visitUnqualName( TL.getAs().getTypePtr()->getDecl()->getName())) return false; break; case TypeLoc::TemplateSpecialization: - if (VisitUnqualName(TL.getAs() + if (visitUnqualName(TL.getAs() .getTypePtr() ->getTemplateName() .getAsTemplateDecl() @@ -67,7 +67,7 @@ public: return false; break; case TypeLoc::Typedef: - if (VisitUnqualName( + if (visitUnqualName( TL.getAs().getTypePtr()->getDecl()->getName())) return false; break; @@ -97,7 +97,7 @@ public: bool VisitDeclRefExpr(DeclRefExpr *S) { DeclarationName Name = S->getNameInfo().getName(); return S->getQualifierLoc() || !Name.isIdentifier() || - !VisitUnqualName(Name.getAsIdentifierInfo()->getName()); + !visitUnqualName(Name.getAsIdentifierInfo()->getName()); } private: @@ -160,11 +160,11 @@ SourceLocation UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation( return Result; } -static bool IsCVR(Token T) { +static bool isCvr(Token T) { return T.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict); } -static bool IsSpecifier(Token T) { +static bool isSpecifier(Token T) { return T.isOneOf(tok::kw_constexpr, tok::kw_inline, tok::kw_extern, tok::kw_static, tok::kw_friend, tok::kw_virtual); } @@ -192,8 +192,8 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, Token Tok) { if (T.is(tok::eof)) break; - bool Qual = IsCVR(T); - bool Spec = IsSpecifier(T); + bool Qual = isCvr(T); + bool Spec = isSpecifier(T); CT.isQualifier &= Qual; CT.isSpecifier &= Spec; ContainsQualifiers |= Qual; diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index f3e8506..a12a056 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp @@ -58,13 +58,13 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) { return; } - auto printPolicy = PrintingPolicy(getLangOpts()); - printPolicy.SuppressScope = true; - printPolicy.ConstantArraySizeAsWritten = true; - printPolicy.UseVoidForZeroParams = false; - printPolicy.PrintInjectedClassNameWithArguments = false; + PrintingPolicy PrintPolicy(getLangOpts()); + PrintPolicy.SuppressScope = true; + PrintPolicy.ConstantArraySizeAsWritten = true; + PrintPolicy.UseVoidForZeroParams = false; + PrintPolicy.PrintInjectedClassNameWithArguments = false; - std::string Type = MatchedDecl->getUnderlyingType().getAsString(printPolicy); + std::string Type = MatchedDecl->getUnderlyingType().getAsString(PrintPolicy); std::string Name = MatchedDecl->getNameAsString(); SourceRange ReplaceRange = MatchedDecl->getSourceRange(); diff --git a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp index 8ababfe..b108f75 100644 --- a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp +++ b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp @@ -38,7 +38,7 @@ void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) { // Adds the type and expression of a buffer that is used in the MPI call // expression to the captured containers. - auto addBuffer = [&CE, &Result, &BufferTypes, + auto AddBuffer = [&CE, &Result, &BufferTypes, &BufferExprs](const size_t BufferIdx) { // Skip null pointer constants and in place 'operators'. if (CE->getArg(BufferIdx)->isNullPointerConstant( @@ -61,18 +61,18 @@ void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) { // MPI call expression. The number passed to the lambda corresponds to the // argument index of the currently verified MPI function call. if (FuncClassifier.isPointToPointType(Identifier)) { - addBuffer(0); + AddBuffer(0); } else if (FuncClassifier.isCollectiveType(Identifier)) { if (FuncClassifier.isReduceType(Identifier)) { - addBuffer(0); - addBuffer(1); + AddBuffer(0); + AddBuffer(1); } else if (FuncClassifier.isScatterType(Identifier) || FuncClassifier.isGatherType(Identifier) || FuncClassifier.isAlltoallType(Identifier)) { - addBuffer(0); - addBuffer(3); + AddBuffer(0); + AddBuffer(3); } else if (FuncClassifier.isBcastType(Identifier)) { - addBuffer(0); + AddBuffer(0); } } @@ -81,9 +81,9 @@ void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) { void BufferDerefCheck::checkBuffers(ArrayRef BufferTypes, ArrayRef BufferExprs) { - for (size_t i = 0; i < BufferTypes.size(); ++i) { + for (size_t I = 0; I < BufferTypes.size(); ++I) { unsigned IndirectionCount = 0; - const Type *BufferType = BufferTypes[i]; + const Type *BufferType = BufferTypes[I]; llvm::SmallVector Indirections; // Capture the depth and types of indirections for the passed buffer. @@ -120,7 +120,7 @@ void BufferDerefCheck::checkBuffers(ArrayRef BufferTypes, } } - const auto Loc = BufferExprs[i]->getSourceRange().getBegin(); + const auto Loc = BufferExprs[I]->getSourceRange().getBegin(); diag(Loc, "buffer is insufficiently dereferenced: %0") << IndirectionDesc; } } diff --git a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp index f305ddf..2d8da68 100644 --- a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp +++ b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp @@ -216,9 +216,9 @@ static bool isTypedefTypeMatching(const TypedefType *const Typedef, {"uint8_t", "MPI_UINT8_T"}, {"uint16_t", "MPI_UINT16_T"}, {"uint32_t", "MPI_UINT32_T"}, {"uint64_t", "MPI_UINT64_T"}}; - const auto it = FixedWidthMatches.find(Typedef->getDecl()->getName()); + const auto It = FixedWidthMatches.find(Typedef->getDecl()->getName()); // Check if the typedef is known and not matching the MPI datatype. - if (it != FixedWidthMatches.end() && it->getValue() != MPIDatatype) { + if (It != FixedWidthMatches.end() && It->getValue() != MPIDatatype) { BufferTypeName = std::string(Typedef->getDecl()->getName()); return false; } @@ -231,8 +231,8 @@ static bool isTypedefTypeMatching(const TypedefType *const Typedef, /// \param idx argument index /// /// \returns type of the argument -static const Type *argumentType(const CallExpr *const CE, const size_t idx) { - const QualType QT = CE->getArg(idx)->IgnoreImpCasts()->getType(); +static const Type *argumentType(const CallExpr *const CE, const size_t Idx) { + const QualType QT = CE->getArg(Idx)->IgnoreImpCasts()->getType(); return QT.getTypePtr()->getPointeeOrArrayElementType(); } @@ -257,8 +257,8 @@ void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) { // Adds a buffer, MPI datatype pair of an MPI call expression to the // containers. For buffers, the type and expression is captured. - auto addPair = [&CE, &Result, &BufferTypes, &BufferExprs, &MPIDatatypes]( - const size_t BufferIdx, const size_t DatatypeIdx) { + auto AddPair = [&CE, &Result, &BufferTypes, &BufferExprs, &MPIDatatypes]( + const size_t BufferIdx, const size_t DatatypeIdx) { // Skip null pointer constants and in place 'operators'. if (CE->getArg(BufferIdx)->isNullPointerConstant( *Result.Context, Expr::NPC_ValueDependentIsNull) || @@ -282,18 +282,18 @@ void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) { // Collect all buffer, MPI datatype pairs for the inspected call expression. if (FuncClassifier.isPointToPointType(Identifier)) { - addPair(0, 2); + AddPair(0, 2); } else if (FuncClassifier.isCollectiveType(Identifier)) { if (FuncClassifier.isReduceType(Identifier)) { - addPair(0, 3); - addPair(1, 3); + AddPair(0, 3); + AddPair(1, 3); } else if (FuncClassifier.isScatterType(Identifier) || FuncClassifier.isGatherType(Identifier) || FuncClassifier.isAlltoallType(Identifier)) { - addPair(0, 2); - addPair(3, 5); + AddPair(0, 2); + AddPair(3, 5); } else if (FuncClassifier.isBcastType(Identifier)) { - addPair(0, 2); + AddPair(0, 2); } } checkArguments(BufferTypes, BufferExprs, MPIDatatypes, getLangOpts()); @@ -305,28 +305,28 @@ void TypeMismatchCheck::checkArguments(ArrayRef BufferTypes, const LangOptions &LO) { std::string BufferTypeName; - for (size_t i = 0; i < MPIDatatypes.size(); ++i) { - const Type *const BT = BufferTypes[i]; + for (size_t I = 0; I < MPIDatatypes.size(); ++I) { + const Type *const BT = BufferTypes[I]; bool Error = false; if (const auto *Typedef = BT->getAs()) { Error = !isTypedefTypeMatching(Typedef, BufferTypeName, - std::string(MPIDatatypes[i])); + std::string(MPIDatatypes[I])); } else if (const auto *Complex = BT->getAs()) { Error = !isCComplexTypeMatching(Complex, BufferTypeName, - std::string(MPIDatatypes[i]), LO); + std::string(MPIDatatypes[I]), LO); } else if (const auto *Template = BT->getAs()) { Error = !isCXXComplexTypeMatching(Template, BufferTypeName, - std::string(MPIDatatypes[i]), LO); + std::string(MPIDatatypes[I]), LO); } else if (const auto *Builtin = BT->getAs()) { Error = !isBuiltinTypeMatching(Builtin, BufferTypeName, - std::string(MPIDatatypes[i]), LO); + std::string(MPIDatatypes[I]), LO); } if (Error) { - const auto Loc = BufferExprs[i]->getSourceRange().getBegin(); + const auto Loc = BufferExprs[I]->getSourceRange().getBegin(); diag(Loc, "buffer type '%0' does not match the MPI datatype '%1'") - << BufferTypeName << MPIDatatypes[i]; + << BufferTypeName << MPIDatatypes[I]; } } } diff --git a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp index 956cb79..35b5bb8 100644 --- a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "ForbiddenSubclassingCheck.h" +#include "../utils/OptionsUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallVector.h" -#include "../utils/OptionsUtils.h" using namespace clang::ast_matchers; diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp index b4e6d0e..758d397 100644 --- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "PropertyDeclarationCheck.h" -#include #include "../utils/OptionsUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" @@ -15,6 +14,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Regex.h" +#include using namespace clang::ast_matchers; diff --git a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp index 0d2efb3..0b32966 100644 --- a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp @@ -21,21 +21,21 @@ namespace performance { namespace { -llvm::Optional MakeCharacterLiteral(const StringLiteral *Literal) { +llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) { std::string Result; { llvm::raw_string_ostream OS(Result); Literal->outputString(OS); } // Now replace the " with '. - auto pos = Result.find_first_of('"'); - if (pos == Result.npos) + auto Pos = Result.find_first_of('"'); + if (Pos == Result.npos) return llvm::None; - Result[pos] = '\''; - pos = Result.find_last_of('"'); - if (pos == Result.npos) + Result[Pos] = '\''; + Pos = Result.find_last_of('"'); + if (Pos == Result.npos) return llvm::None; - Result[pos] = '\''; + Result[Pos] = '\''; return Result; } @@ -83,7 +83,7 @@ void FasterStringFindCheck::check(const MatchFinder::MatchResult &Result) { const auto *Literal = Result.Nodes.getNodeAs("literal"); const auto *FindFunc = Result.Nodes.getNodeAs("func"); - auto Replacement = MakeCharacterLiteral(Literal); + auto Replacement = makeCharacterLiteral(Literal); if (!Replacement) return; diff --git a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp index 38ede42..738e376 100644 --- a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp @@ -24,10 +24,10 @@ namespace performance { // The subtelty is that in some cases (user defined conversions), we can // get to ImplicitCastExpr inside each other, with the outer one a NoOp. In this // case we skip the first cast expr. -static bool IsNonTrivialImplicitCast(const Stmt *ST) { +static bool isNonTrivialImplicitCast(const Stmt *ST) { if (const auto *ICE = dyn_cast(ST)) { return (ICE->getCastKind() != CK_NoOp) || - IsNonTrivialImplicitCast(ICE->getSubExpr()); + isNonTrivialImplicitCast(ICE->getSubExpr()); } return false; } @@ -81,7 +81,7 @@ void ImplicitConversionInLoopCheck::check( // iterator returns a value instead of a reference, and the loop variable // is a reference. This situation is fine (it probably produces the same // code at the end). - if (IsNonTrivialImplicitCast(Materialized->getSubExpr())) + if (isNonTrivialImplicitCast(Materialized->getSubExpr())) ReportAndFix(Result.Context, VD, OperatorCall); } diff --git a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp index c883fc2..f73643f 100644 --- a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp @@ -69,7 +69,7 @@ void InefficientStringConcatenationCheck::check( const auto *LhsStr = Result.Nodes.getNodeAs("lhsStr"); const auto *PlusOperator = Result.Nodes.getNodeAs("plusOperator"); - const auto DiagMsg = + const char *DiagMsg = "string concatenation results in allocation of unnecessary temporary " "strings; consider using 'operator+=' or 'string::append()' instead"; diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp index 776a8ca..f7c5112 100644 --- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "InefficientVectorOperationCheck.h" +#include "../utils/DeclRefExprUtils.h" +#include "../utils/OptionsUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" -#include "../utils/DeclRefExprUtils.h" -#include "../utils/OptionsUtils.h" using namespace clang::ast_matchers; diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp index 0cb1b82..7ff13fe 100644 --- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp @@ -16,7 +16,7 @@ namespace clang { namespace tidy { namespace performance { -static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, +static void replaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, const SourceManager &SM, const LangOptions &LangOpts) { const Expr *Arg = Call->getArg(0); @@ -104,13 +104,13 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) { << (IsConstArg && IsVariable && !IsTriviallyCopyable) << Var << Arg->getType(); - ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts()); + replaceCallWithArg(CallMove, Diag, SM, getLangOpts()); } else if (ReceivingExpr) { auto Diag = diag(FileMoveRange.getBegin(), "passing result of std::move() as a const reference " "argument; no move will actually happen"); - ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts()); + replaceCallWithArg(CallMove, Diag, SM, getLangOpts()); } } diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp index a35220a..8f91200 100644 --- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp @@ -52,10 +52,10 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { constexpr BuiltinType::Kind DoubleTy = BuiltinType::Double; constexpr BuiltinType::Kind LongDoubleTy = BuiltinType::LongDouble; - auto hasBuiltinTyParam = [](int Pos, BuiltinType::Kind Kind) { + auto HasBuiltinTyParam = [](int Pos, BuiltinType::Kind Kind) { return hasParameter(Pos, hasType(isBuiltinType(Kind))); }; - auto hasBuiltinTyArg = [](int Pos, BuiltinType::Kind Kind) { + auto HasBuiltinTyArg = [](int Pos, BuiltinType::Kind Kind) { return hasArgument(Pos, hasType(isBuiltinType(Kind))); }; @@ -69,8 +69,8 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { "::tanh", "::tgamma", "::trunc", "::llround", "::lround"); Finder->addMatcher( callExpr(callee(functionDecl(OneDoubleArgFns, parameterCountIs(1), - hasBuiltinTyParam(0, DoubleTy))), - hasBuiltinTyArg(0, FloatTy)) + HasBuiltinTyParam(0, DoubleTy))), + HasBuiltinTyArg(0, FloatTy)) .bind("call"), this); @@ -80,20 +80,20 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { "::nextafter", "::pow", "::remainder"); Finder->addMatcher( callExpr(callee(functionDecl(TwoDoubleArgFns, parameterCountIs(2), - hasBuiltinTyParam(0, DoubleTy), - hasBuiltinTyParam(1, DoubleTy))), - hasBuiltinTyArg(0, FloatTy), hasBuiltinTyArg(1, FloatTy)) + HasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(1, DoubleTy))), + HasBuiltinTyArg(0, FloatTy), HasBuiltinTyArg(1, FloatTy)) .bind("call"), this); // Match calls to fma(double, double, double) where all args are floats. Finder->addMatcher( callExpr(callee(functionDecl(hasName("::fma"), parameterCountIs(3), - hasBuiltinTyParam(0, DoubleTy), - hasBuiltinTyParam(1, DoubleTy), - hasBuiltinTyParam(2, DoubleTy))), - hasBuiltinTyArg(0, FloatTy), hasBuiltinTyArg(1, FloatTy), - hasBuiltinTyArg(2, FloatTy)) + HasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(1, DoubleTy), + HasBuiltinTyParam(2, DoubleTy))), + HasBuiltinTyArg(0, FloatTy), HasBuiltinTyArg(1, FloatTy), + HasBuiltinTyArg(2, FloatTy)) .bind("call"), this); @@ -101,10 +101,10 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(callee(functionDecl( hasName("::frexp"), parameterCountIs(2), - hasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(0, DoubleTy), hasParameter(1, parmVarDecl(hasType(pointerType( pointee(isBuiltinType(IntTy)))))))), - hasBuiltinTyArg(0, FloatTy)) + HasBuiltinTyArg(0, FloatTy)) .bind("call"), this); @@ -112,9 +112,9 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { // float. Finder->addMatcher( callExpr(callee(functionDecl(hasName("::nexttoward"), parameterCountIs(2), - hasBuiltinTyParam(0, DoubleTy), - hasBuiltinTyParam(1, LongDoubleTy))), - hasBuiltinTyArg(0, FloatTy)) + HasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(1, LongDoubleTy))), + HasBuiltinTyArg(0, FloatTy)) .bind("call"), this); @@ -124,28 +124,28 @@ void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { callExpr( callee(functionDecl( hasName("::remquo"), parameterCountIs(3), - hasBuiltinTyParam(0, DoubleTy), hasBuiltinTyParam(1, DoubleTy), + HasBuiltinTyParam(0, DoubleTy), HasBuiltinTyParam(1, DoubleTy), hasParameter(2, parmVarDecl(hasType(pointerType( pointee(isBuiltinType(IntTy)))))))), - hasBuiltinTyArg(0, FloatTy), hasBuiltinTyArg(1, FloatTy)) + HasBuiltinTyArg(0, FloatTy), HasBuiltinTyArg(1, FloatTy)) .bind("call"), this); // Match calls to scalbln(double, long) where the first arg is a float. Finder->addMatcher( callExpr(callee(functionDecl(hasName("::scalbln"), parameterCountIs(2), - hasBuiltinTyParam(0, DoubleTy), - hasBuiltinTyParam(1, LongTy))), - hasBuiltinTyArg(0, FloatTy)) + HasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(1, LongTy))), + HasBuiltinTyArg(0, FloatTy)) .bind("call"), this); // Match calls to scalbn(double, int) where the first arg is a float. Finder->addMatcher( callExpr(callee(functionDecl(hasName("::scalbn"), parameterCountIs(2), - hasBuiltinTyParam(0, DoubleTy), - hasBuiltinTyParam(1, IntTy))), - hasBuiltinTyArg(0, FloatTy)) + HasBuiltinTyParam(0, DoubleTy), + HasBuiltinTyParam(1, IntTy))), + HasBuiltinTyArg(0, FloatTy)) .bind("call"), this); diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp index 06cfb24..f63dbab 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -127,7 +127,7 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization( utils::options::parseStringList(Options.get("AllowedTypes", ""))) {} void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) { - auto localVarCopiedFrom = [this](const internal::Matcher &CopyCtorArg) { + auto LocalVarCopiedFrom = [this](const internal::Matcher &CopyCtorArg) { return compoundStmt( forEachDescendant( declStmt( @@ -153,11 +153,11 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) { .bind("blockStmt"); }; - Finder->addMatcher(localVarCopiedFrom(anyOf(isConstRefReturningFunctionCall(), + Finder->addMatcher(LocalVarCopiedFrom(anyOf(isConstRefReturningFunctionCall(), isConstRefReturningMethodCall())), this); - Finder->addMatcher(localVarCopiedFrom(declRefExpr( + Finder->addMatcher(LocalVarCopiedFrom(declRefExpr( to(varDecl(hasLocalStorage()).bind(OldVarDeclId)))), this); } @@ -181,8 +181,8 @@ void UnnecessaryCopyInitialization::check( // A constructor that looks like T(const T& t, bool arg = false) counts as a // copy only when it is called with default arguments for the arguments after // the first. - for (unsigned int i = 1; i < CtorCall->getNumArgs(); ++i) - if (!CtorCall->getArg(i)->isDefaultArgument()) + for (unsigned int I = 1; I < CtorCall->getNumArgs(); ++I) + if (!CtorCall->getArg(I)->isDefaultArgument()) return; if (OldVar == nullptr) { diff --git a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp index cbd6fdd..b8367d6 100644 --- a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp +++ b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp @@ -39,9 +39,8 @@ public: std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler, StringRef File) override { // Create and set diagnostics engine - auto ExternalDiagEngine = &Compiler.getDiagnostics(); - auto DiagConsumer = - new ClangTidyDiagnosticConsumer(*Context, ExternalDiagEngine); + auto *DiagConsumer = + new ClangTidyDiagnosticConsumer(*Context, &Compiler.getDiagnostics()); auto DiagEngine = std::make_unique( new DiagnosticIDs, new DiagnosticOptions, DiagConsumer); Context->setDiagnosticsEngine(DiagEngine.get()); diff --git a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp index 9391670..65d7c17 100644 --- a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp @@ -39,7 +39,7 @@ AST_MATCHER(FunctionDecl, isVectorFunction) { } // namespace -static StringRef TrySuggestPPC(StringRef Name) { +static StringRef trySuggestPpc(StringRef Name) { if (!Name.consume_front("vec_")) return {}; @@ -54,7 +54,7 @@ static StringRef TrySuggestPPC(StringRef Name) { .Default({}); } -static StringRef TrySuggestX86(StringRef Name) { +static StringRef trySuggestX86(StringRef Name) { if (!(Name.consume_front("_mm_") || Name.consume_front("_mm256_") || Name.consume_front("_mm512_"))) return {}; @@ -120,11 +120,11 @@ void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) { case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: - New = TrySuggestPPC(Old); + New = trySuggestPpc(Old); break; case llvm::Triple::x86: case llvm::Triple::x86_64: - New = TrySuggestX86(Old); + New = trySuggestX86(Old); break; } diff --git a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp index 91e1495..aed01ab 100644 --- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp +++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp @@ -47,7 +47,7 @@ void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) { } // Re-lex the tokens to get precise location of last 'const' -static llvm::Optional ConstTok(CharSourceRange Range, +static llvm::Optional constTok(CharSourceRange Range, const MatchFinder::MatchResult &Result) { const SourceManager &Sources = *Result.SourceManager; std::pair LocInfo = @@ -86,9 +86,9 @@ void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) { "declaration; const-qualification of parameters only has an " "effect in function definitions"); if (Param->getName().empty()) { - for (unsigned int i = 0; i < Func->getNumParams(); ++i) { - if (Param == Func->getParamDecl(i)) { - Diag << (i + 1); + for (unsigned int I = 0; I < Func->getNumParams(); ++I) { + if (Param == Func->getParamDecl(I)) { + Diag << (I + 1); break; } } @@ -109,7 +109,7 @@ void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) { if (!FileRange.isValid()) return; - auto Tok = ConstTok(FileRange, Result); + auto Tok = constTok(FileRange, Result); if (!Tok) return; Diag << FixItHint::CreateRemoval( diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 64e182b..1123238 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -139,18 +139,19 @@ void BracesAroundStatementsCheck::check( const ASTContext *Context = Result.Context; // Get location of closing parenthesis or 'do' to insert opening brace. - if (auto S = Result.Nodes.getNodeAs("for")) { + if (const auto *S = Result.Nodes.getNodeAs("for")) { checkStmt(Result, S->getBody(), S->getRParenLoc()); - } else if (auto S = Result.Nodes.getNodeAs("for-range")) { + } else if (const auto *S = + Result.Nodes.getNodeAs("for-range")) { checkStmt(Result, S->getBody(), S->getRParenLoc()); - } else if (auto S = Result.Nodes.getNodeAs("do")) { + } else if (const auto *S = Result.Nodes.getNodeAs("do")) { checkStmt(Result, S->getBody(), S->getDoLoc(), S->getWhileLoc()); - } else if (auto S = Result.Nodes.getNodeAs("while")) { + } else if (const auto *S = Result.Nodes.getNodeAs("while")) { SourceLocation StartLoc = findRParenLoc(S, SM, Context); if (StartLoc.isInvalid()) return; checkStmt(Result, S->getBody(), StartLoc); - } else if (auto S = Result.Nodes.getNodeAs("if")) { + } else if (const auto *S = Result.Nodes.getNodeAs("if")) { SourceLocation StartLoc = findRParenLoc(S, SM, Context); if (StartLoc.isInvalid()) return; diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp index 96854bf..88a422a 100644 --- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp @@ -223,14 +223,14 @@ class FunctionASTVisitor final std::stack> BinaryOperatorsStack; public: - bool TraverseStmtWithIncreasedNestingLevel(Stmt *Node) { + bool traverseStmtWithIncreasedNestingLevel(Stmt *Node) { ++CurrentNestingLevel; bool ShouldContinue = Base::TraverseStmt(Node); --CurrentNestingLevel; return ShouldContinue; } - bool TraverseDeclWithIncreasedNestingLevel(Decl *Node) { + bool traverseDeclWithIncreasedNestingLevel(Decl *Node) { ++CurrentNestingLevel; bool ShouldContinue = Base::TraverseDecl(Node); --CurrentNestingLevel; @@ -272,15 +272,15 @@ public: if (!TraverseStmt(Node->getCond())) return false; } else { - if (!TraverseStmtWithIncreasedNestingLevel(Node->getInit())) + if (!traverseStmtWithIncreasedNestingLevel(Node->getInit())) return false; - if (!TraverseStmtWithIncreasedNestingLevel(Node->getCond())) + if (!traverseStmtWithIncreasedNestingLevel(Node->getCond())) return false; } // "Then" always increases nesting level. - if (!TraverseStmtWithIncreasedNestingLevel(Node->getThen())) + if (!traverseStmtWithIncreasedNestingLevel(Node->getThen())) return false; if (!Node->getElse()) @@ -305,7 +305,7 @@ public: } // "Else" always increases nesting level. - return TraverseStmtWithIncreasedNestingLevel(Node->getElse()); + return traverseStmtWithIncreasedNestingLevel(Node->getElse()); } // The currently-being-processed stack entry, which is always the top. @@ -447,7 +447,7 @@ public: if (!(Reasons & CognitiveComplexity::Criteria::IncrementNesting)) return Base::TraverseStmt(Node); - return TraverseStmtWithIncreasedNestingLevel(Node); + return traverseStmtWithIncreasedNestingLevel(Node); } // The parameter MainAnalyzedFunction is needed to differentiate between the @@ -481,7 +481,7 @@ public: CC.account(Node->getBeginLoc(), CurrentNestingLevel, CognitiveComplexity::Criteria::IncrementNesting); - return TraverseDeclWithIncreasedNestingLevel(Node); + return traverseDeclWithIncreasedNestingLevel(Node); } CognitiveComplexity CC; diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index d33040a..b862efe 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -393,12 +393,11 @@ static bool isParamInMainLikeFunction(const ParmVarDecl &ParmDecl, "(^[Mm]ain([_A-Z]|$))|([a-z0-9_]Main([_A-Z]|$))|(_main(_|$))"); assert(Matcher.isValid() && "Invalid Matcher for main like functions."); return Matcher.match(FDecl->getName()); - } else { - static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]" - "ain([_A-Z]|$))|(_wmain(_|$))"); - assert(Matcher.isValid() && "Invalid Matcher for wmain like functions."); - return Matcher.match(FDecl->getName()); } + static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]" + "ain([_A-Z]|$))|(_wmain(_|$))"); + assert(Matcher.isValid() && "Invalid Matcher for wmain like functions."); + return Matcher.match(FDecl->getName()); } static std::string diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index 0ff2c06..51e3e2c 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -260,21 +260,22 @@ void ImplicitBoolConversionCheck::storeOptions( } void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { - auto exceptionCases = + auto ExceptionCases = expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())), - has(ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))), + has(ignoringImplicit( + memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))), hasParent(explicitCastExpr()))); - auto implicitCastFromBool = implicitCastExpr( + auto ImplicitCastFromBool = implicitCastExpr( anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating), // Prior to C++11 cast from bool literal to pointer was allowed. allOf(anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)), hasSourceExpression(cxxBoolLiteral()))), hasSourceExpression(expr(hasType(booleanType()))), - unless(exceptionCases)); - auto boolXor = - binaryOperator(hasOperatorName("^"), hasLHS(implicitCastFromBool), - hasRHS(implicitCastFromBool)); + unless(ExceptionCases)); + auto BoolXor = + binaryOperator(hasOperatorName("^"), hasLHS(ImplicitCastFromBool), + hasRHS(ImplicitCastFromBool)); Finder->addMatcher( traverse(TK_AsIs, implicitCastExpr( @@ -288,7 +289,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { unless(hasParent( stmt(anyOf(ifStmt(), whileStmt()), has(declStmt())))), // Exclude cases common to implicit cast to and from bool. - unless(exceptionCases), unless(has(boolXor)), + unless(ExceptionCases), unless(has(BoolXor)), // Retrieve also parent statement, to check if we need // additional parens in replacement. anyOf(hasParent(stmt().bind("parentStmt")), anything()), @@ -297,30 +298,30 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { .bind("implicitCastToBool")), this); - auto boolComparison = binaryOperator(hasAnyOperatorName("==", "!="), - hasLHS(implicitCastFromBool), - hasRHS(implicitCastFromBool)); - auto boolOpAssignment = binaryOperator(hasAnyOperatorName("|=", "&="), + auto BoolComparison = binaryOperator(hasAnyOperatorName("==", "!="), + hasLHS(ImplicitCastFromBool), + hasRHS(ImplicitCastFromBool)); + auto BoolOpAssignment = binaryOperator(hasAnyOperatorName("|=", "&="), hasLHS(expr(hasType(booleanType())))); - auto bitfieldAssignment = binaryOperator( + auto BitfieldAssignment = binaryOperator( hasLHS(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))); - auto bitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer( + auto BitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer( withInitializer(equalsBoundNode("implicitCastFromBool")), forField(hasBitWidth(1))))); Finder->addMatcher( traverse( TK_AsIs, implicitCastExpr( - implicitCastFromBool, + ImplicitCastFromBool, // Exclude comparisons of bools, as they are always cast to // integers in such context: // bool_expr_a == bool_expr_b // bool_expr_a != bool_expr_b unless(hasParent( - binaryOperator(anyOf(boolComparison, boolXor, - boolOpAssignment, bitfieldAssignment)))), + binaryOperator(anyOf(BoolComparison, BoolXor, + BoolOpAssignment, BitfieldAssignment)))), implicitCastExpr().bind("implicitCastFromBool"), - unless(hasParent(bitfieldConstruct)), + unless(hasParent(BitfieldConstruct)), // Check also for nested casts, for example: bool -> int -> float. anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")), anything()), diff --git a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp index 7983436..3e5b71f 100644 --- a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp @@ -91,7 +91,7 @@ public: // `-ImplicitCastExpr // (possibly `-UnaryOperator Deref) // `-CXXThisExpr 'S *' this - bool VisitUser(const ImplicitCastExpr *Cast) { + bool visitUser(const ImplicitCastExpr *Cast) { if (Cast->getCastKind() != CK_NoOp) return false; // Stop traversal. @@ -115,14 +115,14 @@ public: // ((const S*)this)->Member if (const auto *Member = dyn_cast(Parent)) - return VisitUser(Member, /*OnConstObject=*/true); + return visitUser(Member, /*OnConstObject=*/true); return false; // Stop traversal. } // If OnConstObject is true, then this is a MemberExpr using // a constant this, i.e. 'const S' or 'const S *'. - bool VisitUser(const MemberExpr *Member, bool OnConstObject) { + bool visitUser(const MemberExpr *Member, bool OnConstObject) { if (Member->isBoundMemberFunction(Ctxt)) { if (!OnConstObject || Member->getFoundDecl().getAccess() != AS_public) { // Non-public non-static member functions might not preserve the @@ -159,7 +159,7 @@ public: } if (const auto *M = dyn_cast_or_null(Parent)) - return VisitUser(M, /*OnConstObject=*/false); + return visitUser(M, /*OnConstObject=*/false); return false; // Stop traversal. } @@ -182,7 +182,7 @@ public: // ((const S*)this)->f() // when 'f' is a public member function. if (const auto *Cast = dyn_cast_or_null(Parent)) { - if (VisitUser(Cast)) + if (visitUser(Cast)) return true; // And it's also okay to @@ -190,7 +190,7 @@ public: // (LValueToRValue)(S->t) // when 't' is either of builtin type or a public member. } else if (const auto *Member = dyn_cast_or_null(Parent)) { - if (VisitUser(Member, /*OnConstObject=*/false)) + if (visitUser(Member, /*OnConstObject=*/false)) return true; } @@ -248,7 +248,7 @@ void MakeMemberFunctionConstCheck::check( const MatchFinder::MatchResult &Result) { const auto *Definition = Result.Nodes.getNodeAs("x"); - auto Declaration = Definition->getCanonicalDecl(); + const auto *Declaration = Definition->getCanonicalDecl(); auto Diag = diag(Definition->getLocation(), "method %0 can be made const") << Definition diff --git a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp index 3167d15..77f93f1 100644 --- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp @@ -18,10 +18,10 @@ namespace readability { static const IfStmt *getPrecedingIf(const SourceManager &SM, ASTContext *Context, const IfStmt *If) { - auto parents = Context->getParents(*If); - if (parents.size() != 1) + auto Parents = Context->getParents(*If); + if (Parents.size() != 1) return nullptr; - if (const auto *PrecedingIf = parents[0].get()) { + if (const auto *PrecedingIf = Parents[0].get()) { SourceLocation PreviousElseLoc = PrecedingIf->getElseLoc(); if (SM.getExpansionLineNumber(PreviousElseLoc) == SM.getExpansionLineNumber(If->getIfLoc())) @@ -44,7 +44,7 @@ void MisleadingIndentationCheck::danglingElseCheck(const SourceManager &SM, return; // Find location of first 'if' in a 'if else if' chain. - for (auto PrecedingIf = getPrecedingIf(SM, Context, If); PrecedingIf; + for (const auto *PrecedingIf = getPrecedingIf(SM, Context, If); PrecedingIf; PrecedingIf = getPrecedingIf(SM, Context, PrecedingIf)) IfLoc = PrecedingIf->getIfLoc(); @@ -56,8 +56,8 @@ void MisleadingIndentationCheck::danglingElseCheck(const SourceManager &SM, void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt) { const static StringRef StmtNames[] = {"if", "for", "while"}; - for (unsigned int i = 0; i < CStmt->size() - 1; i++) { - const Stmt *CurrentStmt = CStmt->body_begin()[i]; + for (unsigned int I = 0; I < CStmt->size() - 1; I++) { + const Stmt *CurrentStmt = CStmt->body_begin()[I]; const Stmt *Inner = nullptr; int StmtKind = 0; @@ -89,7 +89,7 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM, SM.getExpansionLineNumber(OuterLoc)) continue; - const Stmt *NextStmt = CStmt->body_begin()[i + 1]; + const Stmt *NextStmt = CStmt->body_begin()[I + 1]; SourceLocation NextLoc = NextStmt->getBeginLoc(); if (NextLoc.isInvalid() || NextLoc.isMacroID()) diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp index 09b03fe..5e018ce 100644 --- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp @@ -62,7 +62,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) { continue; // Skip gmock testing::Unused parameters. - if (auto Typedef = Parm->getType()->getAs()) + if (const auto *Typedef = Parm->getType()->getAs()) if (Typedef->getDecl()->getQualifiedNameAsString() == "testing::Unused") continue; diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp index 003c05f..bd1d8c3 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp @@ -55,16 +55,16 @@ void RedundantControlFlowCheck::check(const MatchFinder::MatchResult &Result) { void RedundantControlFlowCheck::checkRedundantReturn( const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { - CompoundStmt::const_reverse_body_iterator last = Block->body_rbegin(); - if (const auto *Return = dyn_cast(*last)) + CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin(); + if (const auto *Return = dyn_cast(*Last)) issueDiagnostic(Result, Block, Return->getSourceRange(), RedundantReturnDiag); } void RedundantControlFlowCheck::checkRedundantContinue( const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { - CompoundStmt::const_reverse_body_iterator last = Block->body_rbegin(); - if (const auto *Continue = dyn_cast(*last)) + CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin(); + if (const auto *Continue = dyn_cast(*Last)) issueDiagnostic(Result, Block, Continue->getSourceRange(), RedundantContinueDiag); } diff --git a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp index f673dad..dfe3fbc 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -68,7 +68,7 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) { bool MultiVar = false; if (const auto *VD = dyn_cast(D)) { // Is this a multivariable declaration? - for (const auto Other : VD->getDeclContext()->decls()) { + for (const auto *Other : VD->getDeclContext()->decls()) { if (Other != D && Other->getBeginLoc() == VD->getBeginLoc()) { MultiVar = true; break; diff --git a/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp index 822c4cd..46dd82b 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp @@ -40,23 +40,23 @@ public: StringRef Condition = Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), PP.getSourceManager(), PP.getLangOpts()); - CheckMacroRedundancy(Loc, Condition, IfStack, DK_If, DK_If, true); + checkMacroRedundancy(Loc, Condition, IfStack, DK_If, DK_If, true); } void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MacroDefinition) override { std::string MacroName = PP.getSpelling(MacroNameTok); - CheckMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifdef, DK_Ifdef, true); - CheckMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifdef, DK_Ifndef, + checkMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifdef, DK_Ifdef, true); + checkMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifdef, DK_Ifndef, false); } void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MacroDefinition) override { std::string MacroName = PP.getSpelling(MacroNameTok); - CheckMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifndef, DK_Ifndef, + checkMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifndef, DK_Ifndef, true); - CheckMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifndef, DK_Ifdef, + checkMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifndef, DK_Ifdef, false); } @@ -70,7 +70,7 @@ public: } private: - void CheckMacroRedundancy(SourceLocation Loc, StringRef MacroName, + void checkMacroRedundancy(SourceLocation Loc, StringRef MacroName, SmallVector &Stack, DirectiveKind WarningKind, DirectiveKind NoteKind, bool Store) { diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp index 26c8ae5..7a37630 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp @@ -72,18 +72,18 @@ void RedundantStringInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { } void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { - const auto hasStringTypeName = hasAnyNameStdString(StringNames); - const auto hasStringCtorName = + const auto HasStringTypeName = hasAnyNameStdString(StringNames); + const auto HasStringCtorName = hasAnyNameStdString(removeNamespaces(StringNames)); // Match string constructor. const auto StringConstructorExpr = expr( anyOf(cxxConstructExpr(argumentCountIs(1), - hasDeclaration(cxxMethodDecl(hasStringCtorName))), + hasDeclaration(cxxMethodDecl(HasStringCtorName))), // If present, the second argument is the alloc object which must // not be present explicitly. cxxConstructExpr(argumentCountIs(2), - hasDeclaration(cxxMethodDecl(hasStringCtorName)), + hasDeclaration(cxxMethodDecl(HasStringCtorName)), hasArgument(1, cxxDefaultArgExpr())))); // Match a string constructor expression with an empty string literal. @@ -96,7 +96,7 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { hasArgument(0, ignoringImplicit(EmptyStringCtorExpr))); const auto StringType = hasType(hasUnqualifiedDesugaredType( - recordType(hasDeclaration(cxxRecordDecl(hasStringTypeName))))); + recordType(hasDeclaration(cxxRecordDecl(HasStringTypeName))))); const auto EmptyStringInit = traverse( TK_AsIs, expr(ignoringImplicit(anyOf( EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)))); diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp index 7e8ba4e..d450df5 100644 --- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -139,11 +139,11 @@ StringRef negatedOperator(const CXXOperatorCallExpr *OpCall) { return StringRef(); } -std::string asBool(StringRef text, bool NeedsStaticCast) { +std::string asBool(StringRef Text, bool NeedsStaticCast) { if (NeedsStaticCast) - return ("static_cast(" + text + ")").str(); + return ("static_cast(" + Text + ")").str(); - return std::string(text); + return std::string(Text); } bool needsNullPtrComparison(const Expr *E) { @@ -398,8 +398,8 @@ void SimplifyBooleanExprCheck::reportBinOp( bool BoolValue = Bool->getValue(); - auto replaceWithExpression = [this, &Result, LHS, RHS, Bool]( - const Expr *ReplaceWith, bool Negated) { + auto ReplaceWithExpression = [this, &Result, LHS, RHS, + Bool](const Expr *ReplaceWith, bool Negated) { std::string Replacement = replacementExpression(Result, Negated, ReplaceWith); SourceRange Range(LHS->getBeginLoc(), RHS->getEndLoc()); @@ -411,28 +411,28 @@ void SimplifyBooleanExprCheck::reportBinOp( case BO_LAnd: if (BoolValue) { // expr && true -> expr - replaceWithExpression(Other, /*Negated=*/false); + ReplaceWithExpression(Other, /*Negated=*/false); } else { // expr && false -> false - replaceWithExpression(Bool, /*Negated=*/false); + ReplaceWithExpression(Bool, /*Negated=*/false); } break; case BO_LOr: if (BoolValue) { // expr || true -> true - replaceWithExpression(Bool, /*Negated=*/false); + ReplaceWithExpression(Bool, /*Negated=*/false); } else { // expr || false -> expr - replaceWithExpression(Other, /*Negated=*/false); + ReplaceWithExpression(Other, /*Negated=*/false); } break; case BO_EQ: // expr == true -> expr, expr == false -> !expr - replaceWithExpression(Other, /*Negated=*/!BoolValue); + ReplaceWithExpression(Other, /*Negated=*/!BoolValue); break; case BO_NE: // expr != true -> !expr, expr != false -> expr - replaceWithExpression(Other, /*Negated=*/BoolValue); + ReplaceWithExpression(Other, /*Negated=*/BoolValue); break; default: break; diff --git a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp index 3dd646b..2d14b49 100644 --- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp @@ -17,13 +17,13 @@ namespace clang { namespace tidy { namespace readability { -static const char kDefaultTypes[] = +static const char KDefaultTypes[] = "::std::basic_string;::std::basic_string_view;::std::vector;::std::array"; SimplifySubscriptExprCheck::SimplifySubscriptExprCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), Types(utils::options::parseStringList( - Options.get("Types", kDefaultTypes))) { + Options.get("Types", KDefaultTypes))) { } void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) { diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp index eef6253..c4fbeeb 100644 --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp @@ -62,7 +62,7 @@ struct NewSuffix { llvm::Optional FixIt; }; -llvm::Optional GetMacroAwareLocation(SourceLocation Loc, +llvm::Optional getMacroAwareLocation(SourceLocation Loc, const SourceManager &SM) { // Do nothing if the provided location is invalid. if (Loc.isInvalid()) @@ -74,11 +74,11 @@ llvm::Optional GetMacroAwareLocation(SourceLocation Loc, return SpellingLoc; } -llvm::Optional GetMacroAwareSourceRange(SourceRange Loc, +llvm::Optional getMacroAwareSourceRange(SourceRange Loc, const SourceManager &SM) { llvm::Optional Begin = - GetMacroAwareLocation(Loc.getBegin(), SM); - llvm::Optional End = GetMacroAwareLocation(Loc.getEnd(), SM); + getMacroAwareLocation(Loc.getBegin(), SM); + llvm::Optional End = getMacroAwareLocation(Loc.getEnd(), SM); if (!Begin || !End) return llvm::None; return SourceRange(*Begin, *End); @@ -120,7 +120,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal, // The literal may have macro expansion, we need the final expanded src range. llvm::Optional Range = - GetMacroAwareSourceRange(ReplacementDsc.LiteralLocation, SM); + getMacroAwareSourceRange(ReplacementDsc.LiteralLocation, SM); if (!Range) return llvm::None; diff --git a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp index 165acd4..6e83750 100644 --- a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp @@ -42,32 +42,32 @@ namespace tidy { namespace readability { void UseAnyOfAllOfCheck::registerMatchers(MatchFinder *Finder) { - auto returns = [](bool V) { + auto Returns = [](bool V) { return returnStmt(hasReturnValue(cxxBoolLiteral(equals(V)))); }; - auto returnsButNotTrue = + auto ReturnsButNotTrue = returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(true))))); - auto returnsButNotFalse = + auto ReturnsButNotFalse = returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(false))))); Finder->addMatcher( cxxForRangeStmt( - nextStmt(returns(false).bind("final_return")), - hasBody(allOf(hasDescendant(returns(true)), + nextStmt(Returns(false).bind("final_return")), + hasBody(allOf(hasDescendant(Returns(true)), unless(anyOf(hasDescendant(breakStmt()), hasDescendant(gotoStmt()), - hasDescendant(returnsButNotTrue)))))) + hasDescendant(ReturnsButNotTrue)))))) .bind("any_of_loop"), this); Finder->addMatcher( cxxForRangeStmt( - nextStmt(returns(true).bind("final_return")), - hasBody(allOf(hasDescendant(returns(false)), + nextStmt(Returns(true).bind("final_return")), + hasBody(allOf(hasDescendant(Returns(false)), unless(anyOf(hasDescendant(breakStmt()), hasDescendant(gotoStmt()), - hasDescendant(returnsButNotFalse)))))) + hasDescendant(ReturnsButNotFalse)))))) .bind("all_of_loop"), this); } diff --git a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp index 9b8eca1..dae7503 100644 --- a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp @@ -25,14 +25,12 @@ const FunctionDecl *getSurroundingFunction(ASTContext &Context, } bool IsBinaryOrTernary(const Expr *E) { - const Expr *E_base = E->IgnoreImpCasts(); - if (clang::isa(E_base) || - clang::isa(E_base)) { + const Expr *EBase = E->IgnoreImpCasts(); + if (isa(EBase) || isa(EBase)) { return true; } - if (const auto *Operator = - clang::dyn_cast(E_base)) { + if (const auto *Operator = dyn_cast(EBase)) { return Operator->isInfixBinaryOp(); } @@ -56,7 +54,7 @@ bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM, } // If it's a binary OR operation. if (const auto *BO = dyn_cast(Flags)) - if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or) + if (BO->getOpcode() == BinaryOperatorKind::BO_Or) return exprHasBitFlagWithSpelling(BO->getLHS()->IgnoreParenCasts(), SM, LangOpts, FlagName) || exprHasBitFlagWithSpelling(BO->getRHS()->IgnoreParenCasts(), SM, diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp index 1e544f4..9789511 100644 --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp @@ -158,8 +158,8 @@ ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException( } else if (const auto *Try = dyn_cast(St)) { ExceptionInfo Uncaught = throwsException(Try->getTryBlock(), Caught, CallStack); - for (unsigned i = 0; i < Try->getNumHandlers(); ++i) { - const CXXCatchStmt *Catch = Try->getHandler(i); + for (unsigned I = 0; I < Try->getNumHandlers(); ++I) { + const CXXCatchStmt *Catch = Try->getHandler(I); // Everything is catched through 'catch(...)'. if (!Catch->getExceptionDecl()) { diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp index 76e40a3..1d7c11f 100644 --- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp @@ -61,7 +61,7 @@ bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor, return false; } -} +} // namespace ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root, ASTContext *TheContext) diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp index 56c5bca..de75148 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp @@ -17,7 +17,7 @@ namespace utils { namespace { -StringRef RemoveFirstSuffix(StringRef Str, ArrayRef Suffixes) { +StringRef removeFirstSuffix(StringRef Str, ArrayRef Suffixes) { for (StringRef Suffix : Suffixes) { if (Str.endswith(Suffix)) { return Str.substr(0, Str.size() - Suffix.size()); @@ -26,7 +26,7 @@ StringRef RemoveFirstSuffix(StringRef Str, ArrayRef Suffixes) { return Str; } -StringRef MakeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) { +StringRef makeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) { // The list of suffixes to remove from source file names to get the // "canonical" file names. // E.g. tools/sort_includes.cc and tools/sort_includes_test.cc @@ -34,12 +34,12 @@ StringRef MakeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) { // (once canonicalized) will match as being the main include file associated // with the source files. if (Style == IncludeSorter::IS_LLVM) { - return RemoveFirstSuffix( - RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"}); + return removeFirstSuffix( + removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"}); } if (Style == IncludeSorter::IS_Google_ObjC) { StringRef Canonical = - RemoveFirstSuffix(RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", + removeFirstSuffix(removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp", ".mm", ".m"}), {"_unittest", "_regtest", "_test", "Test"}); @@ -52,19 +52,19 @@ StringRef MakeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) { return Canonical.substr( 0, Canonical.find_first_of('+', StartIndex)); } - return RemoveFirstSuffix( - RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), + return removeFirstSuffix( + removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"_unittest", "_regtest", "_test"}); } // Scan to the end of the line and return the offset of the next line. -size_t FindNextLine(const char *Text) { +size_t findNextLine(const char *Text) { size_t EOLIndex = std::strcspn(Text, "\n"); return Text[EOLIndex] == '\0' ? EOLIndex : EOLIndex + 1; } IncludeSorter::IncludeKinds -DetermineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile, +determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile, bool IsAngled, IncludeSorter::IncludeStyle Style) { // Compute the two "canonical" forms of the include's filename sans extension. // The first form is the include's filename without ".h" or "-inl.h" at the @@ -76,7 +76,7 @@ DetermineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile, return IncludeFile.endswith(".h") ? IncludeSorter::IK_CSystemInclude : IncludeSorter::IK_CXXSystemInclude; } - StringRef CanonicalInclude = MakeCanonicalName(IncludeFile, Style); + StringRef CanonicalInclude = makeCanonicalName(IncludeFile, Style); if (CanonicalFile.endswith(CanonicalInclude) || CanonicalInclude.endswith(CanonicalFile)) { return IncludeSorter::IK_MainTUInclude; @@ -127,12 +127,12 @@ IncludeSorter::IncludeSorter(const SourceManager *SourceMgr, const FileID FileID, StringRef FileName, IncludeStyle Style) : SourceMgr(SourceMgr), Style(Style), CurrentFileID(FileID), - CanonicalFile(MakeCanonicalName(FileName, Style)) {} + CanonicalFile(makeCanonicalName(FileName, Style)) {} void IncludeSorter::AddInclude(StringRef FileName, bool IsAngled, SourceLocation HashLocation, SourceLocation EndLocation) { - int Offset = FindNextLine(SourceMgr->getCharacterData(EndLocation)); + int Offset = findNextLine(SourceMgr->getCharacterData(EndLocation)); // Record the relevant location information for this inclusion directive. IncludeLocations[FileName].push_back( @@ -145,7 +145,7 @@ void IncludeSorter::AddInclude(StringRef FileName, bool IsAngled, // Add the included file's name to the appropriate bucket. IncludeKinds Kind = - DetermineIncludeKind(CanonicalFile, FileName, IsAngled, Style); + determineIncludeKind(CanonicalFile, FileName, IsAngled, Style); if (Kind != IK_InvalidInclude) IncludeBucket[Kind].push_back(FileName.str()); } @@ -171,14 +171,15 @@ Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName, } auto IncludeKind = - DetermineIncludeKind(CanonicalFile, FileName, IsAngled, Style); + determineIncludeKind(CanonicalFile, FileName, IsAngled, Style); if (!IncludeBucket[IncludeKind].empty()) { for (const std::string &IncludeEntry : IncludeBucket[IncludeKind]) { if (compareHeaders(FileName, IncludeEntry, Style) < 0) { const auto &Location = IncludeLocations[IncludeEntry][0]; return FixItHint::CreateInsertion(Location.getBegin(), IncludeStmt); - } else if (FileName == IncludeEntry) { + } + if (FileName == IncludeEntry) { return llvm::None; } } @@ -195,9 +196,9 @@ Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName, // include bucket in the file. In that case, we'll want to sort the include // before that bucket. IncludeKinds NonEmptyKind = IK_InvalidInclude; - for (int i = IK_InvalidInclude - 1; i >= 0; --i) { - if (!IncludeBucket[i].empty()) { - NonEmptyKind = static_cast(i); + for (int I = IK_InvalidInclude - 1; I >= 0; --I) { + if (!IncludeBucket[I].empty()) { + NonEmptyKind = static_cast(I); if (NonEmptyKind < IncludeKind) break; } -- 2.7.4