[clang-tools-extra] cbdc3e1 - [clang-tidy][NFC] Fix cppcoreguidelines-init-variables findings
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 27 05:00:08 PDT 2023
Author: Piotr Zegar
Date: 2023-08-27T11:59:03Z
New Revision: cbdc3e1bf9da09911ba353bcd20c6709bda43893
URL: https://github.com/llvm/llvm-project/commit/cbdc3e1bf9da09911ba353bcd20c6709bda43893
DIFF: https://github.com/llvm/llvm-project/commit/cbdc3e1bf9da09911ba353bcd20c6709bda43893.diff
LOG: [clang-tidy][NFC] Fix cppcoreguidelines-init-variables findings
Fix issues found by clang-tidy in clang-tidy source directory.
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp
clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 499144830eabea..47253570e91da6 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -133,7 +133,7 @@ class ErrorReporter {
for (const FileByteRange &FBR : Error.Message.Ranges)
Diag << getRange(FBR);
// FIXME: explore options to support interactive fix selection.
- const llvm::StringMap<Replacements> *ChosenFix;
+ const llvm::StringMap<Replacements> *ChosenFix = nullptr;
if (ApplyFixes != FB_NoFix &&
(ChosenFix = getFixIt(Error, ApplyFixes == FB_FixNotes))) {
for (const auto &FileAndReplacements : *ChosenFix) {
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 8b261268449cf2..3e926236adb451 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -97,7 +97,7 @@ static std::optional<bool> getAsBool(StringRef Value,
return Parsed;
// To maintain backwards compatability, we support parsing numbers as
// booleans, even though its not supported in YAML.
- long long Number;
+ long long Number = 0;
if (!Value.getAsInteger(10, Number))
return Number != 0;
return std::nullopt;
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
index 5688dc16d1106a..121892fd0daa9a 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
@@ -159,7 +159,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
return;
DurationScale Scale = *MaybeScale;
- const Expr *Remainder;
+ const Expr *Remainder = nullptr;
std::optional<DurationScale> NewScale;
// We next handle the cases of multiplication and division.
diff --git a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
index 2eed10bbf6e6cf..fafb029e7de1b4 100644
--- a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
@@ -103,9 +103,9 @@ StrCatCheckResult processCall(const CallExpr *RootCall, bool IsAppend,
} // namespace
void RedundantStrcatCallsCheck::check(const MatchFinder::MatchResult& Result) {
- bool IsAppend;
+ bool IsAppend = false;
- const CallExpr* RootCall;
+ const CallExpr *RootCall = nullptr;
if ((RootCall = Result.Nodes.getNodeAs<CallExpr>("StrCat")))
IsAppend = false;
else if ((RootCall = Result.Nodes.getNodeAs<CallExpr>("StrAppend")))
diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
index 197fa812501601..37eacf565f199d 100644
--- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -203,7 +203,7 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement,
// If increment is binary and not one of +, -, *, /, we can't know the loop
// bounds.
if (const auto *Op = dyn_cast<BinaryOperator>(Increment)) {
- int ConstantValue;
+ int ConstantValue = 0;
if (!extractValue(ConstantValue, Op, Context))
return true;
switch (Op->getOpcode()) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
index e27012a91c3e55..95a7c521eabb0e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -151,7 +151,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
// We are looking for a pointer offset operation,
// with one hand being a pointer, and another one being an offset.
- const Expr *PointerExpr, *IndexExpr;
+ const Expr *PointerExpr = nullptr, *IndexExpr = nullptr;
if (const auto *BO = dyn_cast<BinaryOperator>(E)) {
PointerExpr = BO->getLHS();
IndexExpr = BO->getRHS();
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index bdf388f04a779f..a1f92aae55448c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -163,7 +163,7 @@ static int relativeCharSizesW(BuiltinType::Kind Kind) {
}
static bool isFirstWider(BuiltinType::Kind First, BuiltinType::Kind Second) {
- int FirstSize, SecondSize;
+ int FirstSize = 0, SecondSize = 0;
if ((FirstSize = relativeIntSizes(First)) != 0 &&
(SecondSize = relativeIntSizes(Second)) != 0)
return FirstSize > SecondSize;
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
index bd8a0b359c2e00..41191a3cfed23a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
@@ -29,7 +29,7 @@ bool isExprValueStored(const Expr *E, ASTContext &C) {
DynTypedNodeList P = PMap.getParents(*E);
if (P.size() != 1)
return false;
- const Expr *ParentE;
+ const Expr *ParentE = nullptr;
while ((ParentE = P[0].get<Expr>()) && ParentE->IgnoreParenCasts() == E) {
P = PMap.getParents(P[0]);
if (P.size() != 1)
diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 3e04df656a67a4..95fbca2ad00830 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -76,7 +76,7 @@ void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result
const auto *CondVar = Result.Nodes.getNodeAs<VarDecl>(CondVarStr);
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>(FuncStr);
- const DeclRefExpr *OuterIfVar, *InnerIfVar;
+ const DeclRefExpr *OuterIfVar = nullptr, *InnerIfVar = nullptr;
if (const auto *Inner = Result.Nodes.getNodeAs<DeclRefExpr>(InnerIfVar1Str))
InnerIfVar = Inner;
else
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index efa7dd66c816ea..fd3ca76e68a61b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -480,7 +480,7 @@ bool SignalHandlerCheck::checkFunctionCPP14(
return true;
}
- const FunctionDecl *FBody;
+ const FunctionDecl *FBody = nullptr;
const Stmt *BodyS = FD->getBody(FBody);
if (!BodyS)
return false;
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp b/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
index 3c7e599a1acfa8..3b59d2357fe29b 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
@@ -178,7 +178,7 @@ StringRef classifyReplacement(ConversionKind K) {
void StrToNumCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Call = Result.Nodes.getNodeAs<CallExpr>("expr");
const FunctionDecl *FuncDecl = nullptr;
- ConversionKind Conversion;
+ ConversionKind Conversion = ConversionKind::None;
if (const auto *ConverterFunc =
Result.Nodes.getNodeAs<FunctionDecl>("converter")) {
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index f22c9f599a262f..1b858db511f50a 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -487,7 +487,7 @@ void NarrowingConversionsCheck::handleFloatingCast(const ASTContext &Context,
// not within destination range. We convert the value to the destination
// type and check if the resulting value is infinity.
llvm::APFloat Tmp = Constant.getFloat();
- bool UnusedLosesInfo;
+ bool UnusedLosesInfo = false;
Tmp.convert(Context.getFloatTypeSemantics(ToType->desugar()),
llvm::APFloatBase::rmNearestTiesToEven, &UnusedLosesInfo);
if (Tmp.isInfinity())
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 152db151f78ec7..aac824f15fa570 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -175,8 +175,8 @@ void PreferMemberInitializerCheck::check(
return;
}
- const FieldDecl *Field;
- const Expr *InitValue;
+ const FieldDecl *Field = nullptr;
+ const Expr *InitValue = nullptr;
std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
if (Field) {
if (IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
index f73667f21ae876..fa000e21b281ce 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -62,7 +62,7 @@ bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
return false;
// Short circuit the lookup if we have analyzed this record before.
- bool PreviousIsInterfaceResult;
+ bool PreviousIsInterfaceResult = false;
if (getInterfaceStatus(Node, PreviousIsInterfaceResult))
return PreviousIsInterfaceResult;
diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
index 53c6f5aa7940d9..bb4e1de8cc4b15 100644
--- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -88,8 +88,8 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
tok::kw_signed))
return;
- bool IsSigned;
- unsigned Width;
+ bool IsSigned = false;
+ unsigned Width = 0;
const TargetInfo &TargetInfo = Result.Context->getTargetInfo();
// Look for uses of short, long, long long and their unsigned versions.
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index b100fae2be299b..ce57b9fc3cac10 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -267,8 +267,8 @@ void UpgradeGoogletestCaseCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method")) {
ReplacementText = getNewMethodName(Method->getName());
- bool IsInInstantiation;
- bool IsInTemplate;
+ bool IsInInstantiation = false;
+ bool IsInTemplate = false;
bool AddFix = true;
if (const auto *Call = Result.Nodes.getNodeAs<CXXMemberCallExpr>("call")) {
const auto *Callee = llvm::cast<MemberExpr>(Call->getCallee());
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index ebd20f29a641c0..47dafca2d03ff0 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -95,8 +95,8 @@ void MultiwayPathsCoveredCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
const auto *Switch = Result.Nodes.getNodeAs<SwitchStmt>("switch");
- std::size_t SwitchCaseCount;
- bool SwitchHasDefault;
+ std::size_t SwitchCaseCount = 0;
+ bool SwitchHasDefault = false;
std::tie(SwitchCaseCount, SwitchHasDefault) = countCaseLabels(Switch);
// Checks the sanity of 'switch' statements that actually do define
diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
index 022ac10baae4cc..3fb2e8daaebed9 100644
--- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -143,7 +143,7 @@ void IncludeOrderPPCallbacks::EndOfMainFile() {
// block.
for (unsigned BI = 0, BE = Blocks.size() - 1; BI != BE; ++BI) {
// Find the first include that's not in the right position.
- unsigned I, E;
+ unsigned I = 0, E = 0;
for (I = Blocks[BI], E = Blocks[BI + 1]; I != E; ++I)
if (IncludeIndices[I] != I)
break;
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
index 551f26ab9b9248..5b1b1cd152fffb 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -56,7 +56,7 @@ static llvm::SmallString<64U> skeleton(StringRef Name) {
while (Curr < End) {
const char *Prev = Curr;
- UTF32 CodePoint;
+ UTF32 CodePoint = 0;
ConversionResult Result = convertUTF8Sequence(
reinterpret_cast<const UTF8 **>(&Curr),
reinterpret_cast<const UTF8 *>(End), &CodePoint, strictConversion);
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
index 9fd718c270e598..79ebb2387179ea 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
@@ -38,14 +38,14 @@ int main(int argc, char *argv[]) {
}
llvm::StringRef From = Values[0].trim();
- llvm::UTF32 CodePoint;
+ llvm::UTF32 CodePoint = 0;
From.getAsInteger(16, CodePoint);
SmallVector<llvm::UTF32> To;
SmallVector<StringRef> ToN;
Values[1].split(ToN, ' ', -1, false);
for (StringRef To_ : ToN) {
- llvm::UTF32 ToCodePoint;
+ llvm::UTF32 ToCodePoint = 0;
To_.trim().getAsInteger(16, ToCodePoint);
To.push_back(ToCodePoint);
}
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
index dad6737ab40cda..da7139255bfaab 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -51,7 +51,7 @@ static bool containsMisleadingBidi(StringRef Buffer,
BidiContexts.clear();
continue;
}
- llvm::UTF32 CodePoint;
+ llvm::UTF32 CodePoint = 0;
llvm::ConversionResult Result = llvm::convertUTF8Sequence(
(const llvm::UTF8 **)&CurPtr, (const llvm::UTF8 *)Buffer.end(),
&CodePoint, llvm::strictConversion);
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp
index e1b98b86ecbd66..0448a71260b135 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp
@@ -124,7 +124,7 @@ static bool hasRTLCharacters(StringRef Buffer) {
const char *CurPtr = Buffer.begin();
const char *EndPtr = Buffer.end();
while (CurPtr < EndPtr) {
- llvm::UTF32 CodePoint;
+ llvm::UTF32 CodePoint = 0;
llvm::ConversionResult Result = llvm::convertUTF8Sequence(
(const llvm::UTF8 **)&CurPtr, (const llvm::UTF8 *)EndPtr, &CodePoint,
llvm::strictConversion);
diff --git a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
index 4aaf64c9c53617..0cdd48c13b2a64 100644
--- a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
@@ -51,7 +51,7 @@ void MisplacedConstCheck::check(const MatchFinder::MatchResult &Result) {
QualType CanQT = Var->getType().getCanonicalType();
SourceLocation AliasLoc;
- const char *AliasType;
+ const char *AliasType = nullptr;
if (const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("typedef")) {
AliasLoc = Typedef->getLocation();
AliasType = "typedef";
diff --git a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
index e772bcc9ed771a..32ea0c0cdf48c0 100644
--- a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
@@ -17,7 +17,7 @@ namespace clang::tidy::misc {
namespace {
AST_MATCHER(FunctionDecl, isPlacementOverload) {
- bool New;
+ bool New = false;
switch (Node.getOverloadedOperator()) {
default:
return false;
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index 92a541c9e59be7..fa8343220dd05a 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -1027,7 +1027,7 @@ void RedundantExpressionCheck::checkArithmeticExpr(
const MatchFinder::MatchResult &Result) {
APSInt LhsValue, RhsValue;
const Expr *LhsSymbol = nullptr, *RhsSymbol = nullptr;
- BinaryOperatorKind LhsOpcode, RhsOpcode;
+ BinaryOperatorKind LhsOpcode{}, RhsOpcode{};
if (const auto *ComparisonOperator = Result.Nodes.getNodeAs<BinaryOperator>(
"binop-const-compare-to-sym")) {
@@ -1104,7 +1104,7 @@ void RedundantExpressionCheck::checkBitwiseExpr(
APSInt LhsValue, RhsValue;
const Expr *LhsSymbol = nullptr;
- BinaryOperatorKind LhsOpcode;
+ BinaryOperatorKind LhsOpcode{};
if (!retrieveBinOpIntegerConstantExpr(Result, "lhs", LhsOpcode, LhsSymbol,
LhsValue) ||
!retrieveIntegerConstantExpr(Result, "rhs", RhsValue))
@@ -1180,7 +1180,7 @@ void RedundantExpressionCheck::checkRelationalExpr(
const Expr *LhsExpr = nullptr, *RhsExpr = nullptr;
const Expr *LhsSymbol = nullptr, *RhsSymbol = nullptr;
const Expr *LhsConst = nullptr, *RhsConst = nullptr;
- BinaryOperatorKind LhsOpcode, RhsOpcode;
+ BinaryOperatorKind LhsOpcode{}, RhsOpcode{};
APSInt LhsValue, RhsValue;
if (!retrieveRelationalIntegerConstantExpr(
@@ -1240,7 +1240,7 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
// intentional.
if (areSidesBinaryConstExpressions(BinOp, Result.Context)) {
const Expr *LhsConst = nullptr, *RhsConst = nullptr;
- BinaryOperatorKind MainOpcode, SideOpcode;
+ BinaryOperatorKind MainOpcode{}, SideOpcode{};
if (!retrieveConstExprFromBothSides(BinOp, MainOpcode, SideOpcode,
LhsConst, RhsConst, Result.Context))
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index bf340984bd3811..a37551b42a0e0e 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -962,8 +962,8 @@ void LoopConvertCheck::check(const MatchFinder::MatchResult &Result) {
Confidence ConfidenceLevel(Confidence::CL_Safe);
ASTContext *Context = Result.Context;
- const ForStmt *Loop;
- LoopFixerKind FixerKind;
+ const ForStmt *Loop = nullptr;
+ LoopFixerKind FixerKind{};
RangeDescriptor Descriptor;
if ((Loop = Nodes.getNodeAs<ForStmt>(LoopNameArray))) {
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index afac9f7497ac80..5134eb51a03226 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -310,7 +310,7 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
bodyEmpty(Result.Context, Body);
std::vector<FixItHint> RemoveInitializers;
- unsigned MemberType;
+ unsigned MemberType = 0;
if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(SpecialFunctionDecl)) {
if (Ctor->getNumParams() == 0) {
MemberType = 0;
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index d4e216239ea94d..990e20400fbfcd 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -42,7 +42,7 @@ void recordFixes(const VarDecl &Var, ASTContext &Context,
std::optional<SourceLocation> firstLocAfterNewLine(SourceLocation Loc,
SourceManager &SM) {
- bool Invalid;
+ bool Invalid = false;
const char *TextAfter = SM.getCharacterData(Loc, &Invalid);
if (Invalid) {
return std::nullopt;
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index b5dc09c5f13add..831614148c7c25 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -100,8 +100,8 @@ struct CognitiveComplexity final {
std::pair<unsigned, unsigned short> process() const {
assert(C != Criteria::None && "invalid criteria");
- unsigned MsgId; // The id of the message to output.
- unsigned short Increment; // How much of an increment?
+ unsigned MsgId = 0; // The id of the message to output.
+ unsigned short Increment = 0; // How much of an increment?
if (C == Criteria::All) {
Increment = 1 + Nesting;
@@ -196,8 +196,8 @@ void CognitiveComplexity::account(SourceLocation Loc, unsigned short Nesting,
Details.emplace_back(Loc, Nesting, C);
const Detail &D = Details.back();
- unsigned MsgId;
- unsigned short Increase;
+ unsigned MsgId = 0;
+ unsigned short Increase = 0;
std::tie(MsgId, Increase) = D.process();
Total += Increase;
@@ -242,9 +242,8 @@ class FunctionASTVisitor final
return Base::TraverseIfStmt(Node);
{
- CognitiveComplexity::Criteria Reasons;
-
- Reasons = CognitiveComplexity::Criteria::None;
+ CognitiveComplexity::Criteria Reasons =
+ CognitiveComplexity::Criteria::None;
// "If" increases cognitive complexity.
Reasons |= CognitiveComplexity::Criteria::Increment;
@@ -290,9 +289,8 @@ class FunctionASTVisitor final
return TraverseIfStmt(E, true);
{
- CognitiveComplexity::Criteria Reasons;
-
- Reasons = CognitiveComplexity::Criteria::None;
+ CognitiveComplexity::Criteria Reasons =
+ CognitiveComplexity::Criteria::None;
// "Else" increases cognitive complexity.
Reasons |= CognitiveComplexity::Criteria::Increment;
@@ -549,8 +547,8 @@ void FunctionCognitiveComplexityCheck::check(
// Output all the basic increments of complexity.
for (const auto &Detail : Visitor.CC.Details) {
- unsigned MsgId; // The id of the message to output.
- unsigned short Increase; // How much of an increment?
+ unsigned MsgId = 0; // The id of the message to output.
+ unsigned short Increase = 0; // How much of an increment?
std::tie(MsgId, Increase) = Detail.process();
assert(MsgId < Msgs.size() && "MsgId should always be valid");
// Increase, on the other hand, can be 0.
diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index cffe858c39ad1c..7f3c2cb9a0434c 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -93,7 +93,7 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
IgnoredIntegerValues.resize(IgnoredIntegerValuesInput.size());
llvm::transform(IgnoredIntegerValuesInput, IgnoredIntegerValues.begin(),
[](StringRef Value) {
- int64_t Res;
+ int64_t Res = 0;
Value.getAsInteger(10, Res);
return Res;
});
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 89e0c89fa933ae..26d9287f07049e 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -613,8 +613,8 @@ void SimplifyBooleanExprCheck::reportBinOp(const ASTContext &Context,
const auto *LHS = Op->getLHS()->IgnoreParenImpCasts();
const auto *RHS = Op->getRHS()->IgnoreParenImpCasts();
- const CXXBoolLiteralExpr *Bool;
- const Expr *Other;
+ const CXXBoolLiteralExpr *Bool = nullptr;
+ const Expr *Other = nullptr;
if ((Bool = dyn_cast<CXXBoolLiteralExpr>(LHS)) != nullptr)
Other = RHS;
else if ((Bool = dyn_cast<CXXBoolLiteralExpr>(RHS)) != nullptr)
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index bfca8c3b6c3d45..3eb80019ae753e 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -239,7 +239,7 @@ static bool applyJaroWinklerHeuristic(StringRef Arg, StringRef Param,
std::ptr
diff _t L = 0;
for (std::ptr
diff _t I = 0; I < ParamLen; ++I) {
if (ParamFlags[I] == 1) {
- std::ptr
diff _t J;
+ std::ptr
diff _t J = 0;
for (J = L; J < ArgLen; ++J)
if (ArgFlags[J] == 1) {
L = J + 1;
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 549331c2d9938a..66b5f3922789da 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -128,7 +128,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
// Else keep the naive literal location!
// Get the whole literal from the source buffer.
- bool Invalid;
+ bool Invalid = false;
const StringRef LiteralSourceText = Lexer::getSourceText(
CharSourceRange::getTokenRange(*Range), SM, LO, &Invalid);
assert(!Invalid && "Failed to retrieve the source text.");
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
index 40a3916fde4782..4dd4a95f880aca 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
@@ -14,19 +14,17 @@ namespace clang::tidy::utils {
ExceptionSpecAnalyzer::State
ExceptionSpecAnalyzer::analyze(const FunctionDecl *FuncDecl) {
- ExceptionSpecAnalyzer::State State;
-
// Check if the function has already been analyzed and reuse that result.
const auto CacheEntry = FunctionCache.find(FuncDecl);
if (CacheEntry == FunctionCache.end()) {
- State = analyzeImpl(FuncDecl);
+ ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
// Cache the result of the analysis.
FunctionCache.try_emplace(FuncDecl, State);
- } else
- State = CacheEntry->getSecond();
+ return State;
+ }
- return State;
+ return CacheEntry->getSecond();
}
ExceptionSpecAnalyzer::State
@@ -144,7 +142,7 @@ ExceptionSpecAnalyzer::analyzeFunctionEST(const FunctionDecl *FuncDecl,
return State::NotThrowing;
case CT_Dependent: {
const Expr *NoexceptExpr = FuncProto->getNoexceptExpr();
- bool Result;
+ bool Result = false;
return (NoexceptExpr && !NoexceptExpr->isValueDependent() &&
NoexceptExpr->EvaluateAsBooleanCondition(
Result, FuncDecl->getASTContext(), true) &&
diff --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
index 46c36d62bdd564..cd5cbdc25e10e1 100644
--- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -188,7 +188,7 @@ class HeaderGuardPPCallbacks : public PPCallbacks {
void checkEndifComment(StringRef FileName, SourceLocation EndIf,
StringRef HeaderGuard,
std::vector<FixItHint> &FixIts) {
- size_t EndIfLen;
+ size_t EndIfLen = 0;
if (wouldFixEndifComment(FileName, EndIf, HeaderGuard, &EndIfLen)) {
FixIts.push_back(FixItHint::CreateReplacement(
CharSourceRange::getCharRange(EndIf,
More information about the cfe-commits
mailing list