https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/213959

None

>From 87b96fda17af63dde5cbd787a1b8eabd0a925ec7 Mon Sep 17 00:00:00 2001
From: Victor Baranov <[email protected]>
Date: Tue, 4 Aug 2026 17:21:14 +0300
Subject: [PATCH] [clang-tidy][NFC] Apply readability-redundant-nested-if 2/N

---
 .../cppcoreguidelines/SlicingCheck.cpp        | 10 +--
 .../google/GlobalNamesInHeadersCheck.cpp      | 28 ++++---
 .../llvm/PreferRegisterOverUnsignedCheck.cpp  |  8 +-
 ...referStaticOverAnonymousNamespaceCheck.cpp |  6 +-
 .../llvmlibc/InlineFunctionDeclCheck.cpp      |  6 +-
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 21 +++--
 .../misc/UseInternalLinkageCheck.cpp          | 11 ++-
 .../clang-tidy/modernize/AvoidBindCheck.cpp   | 18 ++---
 .../modernize/AvoidCStyleCastCheck.cpp        | 19 +++--
 .../clang-tidy/modernize/LoopConvertCheck.cpp | 35 ++++-----
 .../clang-tidy/modernize/LoopConvertUtils.cpp | 76 +++++++++----------
 .../clang-tidy/modernize/MacroToEnumCheck.cpp | 10 +--
 .../modernize/MakeSmartPtrCheck.cpp           | 22 +++---
 .../clang-tidy/modernize/PassByValueCheck.cpp | 14 ++--
 .../clang-tidy/modernize/TypeTraitsCheck.cpp  | 18 ++---
 .../clang-tidy/modernize/UseAutoCheck.cpp     |  7 +-
 .../modernize/UseConstraintsCheck.cpp         | 17 ++---
 .../modernize/UseDefaultMemberInitCheck.cpp   | 10 +--
 .../modernize/UseEqualsDeleteCheck.cpp        |  8 +-
 .../clang-tidy/modernize/UseNullptrCheck.cpp  |  9 +--
 20 files changed, 171 insertions(+), 182 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
index fe95dbba68118..47aaf6cfa5189 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
@@ -89,12 +89,10 @@ void SlicingCheck::diagnoseSlicedOverriddenMethods(
     }
   }
   // Recursively process bases.
-  for (const auto &Base : DerivedDecl.bases()) {
-    if (const auto *BaseRecord = Base.getType()->getAsCXXRecordDecl()) {
-      if (BaseRecord->isCompleteDefinition())
-        diagnoseSlicedOverriddenMethods(Call, *BaseRecord, BaseDecl);
-    }
-  }
+  for (const auto &Base : DerivedDecl.bases())
+    if (const auto *BaseRecord = Base.getType()->getAsCXXRecordDecl();
+        BaseRecord && BaseRecord->isCompleteDefinition())
+      diagnoseSlicedOverriddenMethods(Call, *BaseRecord, BaseDecl);
 }
 
 void SlicingCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
index ee0e29b9c5d17..d068764d1fe69 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
@@ -34,23 +34,21 @@ void GlobalNamesInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (D->getBeginLoc().isMacroID())
     return;
 
-  // Ignore if it comes from the "main" file ...
+  // Ignore if it comes from the "main" file unless that file is a header.
   if (Result.SourceManager->isInMainFile(
-          Result.SourceManager->getExpansionLoc(D->getBeginLoc()))) {
-    // unless that file is a header.
-    if (!utils::isSpellingLocInHeaderFile(
-            D->getBeginLoc(), *Result.SourceManager, 
getHeaderFileExtensions()))
-      return;
-  }
+          Result.SourceManager->getExpansionLoc(D->getBeginLoc())) &&
+      !utils::isSpellingLocInHeaderFile(D->getBeginLoc(), 
*Result.SourceManager,
+                                        getHeaderFileExtensions()))
+    return;
 
-  if (const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
-    if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
-      // Anonymous namespaces inject a using directive into the AST to import
-      // the names into the containing namespace.
-      // We should not have them in headers, but there is another warning for
-      // that.
-      return;
-    }
+  if (const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D);
+      UsingDirective &&
+      UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
+    // Anonymous namespaces inject a using directive into the AST to import
+    // the names into the containing namespace.
+    // We should not have them in headers, but there is another warning for
+    // that.
+    return;
   }
 
   diag(D->getBeginLoc(),
diff --git 
a/clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp 
b/clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
index 60baee7fdba6a..4384a1067d581 100644
--- a/clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
@@ -37,10 +37,10 @@ void PreferRegisterOverUnsignedCheck::check(
   bool NeedsQualification = true;
   const DeclContext *Context = UserVarDecl->getDeclContext();
   while (Context) {
-    if (const auto *Namespace = dyn_cast<NamespaceDecl>(Context))
-      if (isa<TranslationUnitDecl>(Namespace->getDeclContext()) &&
-          Namespace->getName() == "llvm")
-        NeedsQualification = false;
+    if (const auto *Namespace = dyn_cast<NamespaceDecl>(Context);
+        Namespace && isa<TranslationUnitDecl>(Namespace->getDeclContext()) &&
+        Namespace->getName() == "llvm")
+      NeedsQualification = false;
     for (const auto *UsingDirective : Context->using_directives()) {
       const NamespaceDecl *Namespace = UsingDirective->getNominatedNamespace();
       if (isa<TranslationUnitDecl>(Namespace->getDeclContext()) &&
diff --git 
a/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
index 59d821e29e75a..afaae90ef172e 100644
--- 
a/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
@@ -24,9 +24,9 @@ AST_MATCHER(VarDecl, isLocalVariable) { return 
Node.isLocalVarDecl(); }
 AST_MATCHER(Decl, isLexicallyInAnonymousNamespace) {
   for (const DeclContext *DC = Node.getLexicalDeclContext(); DC != nullptr;
        DC = DC->getLexicalParent()) {
-    if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
-      if (ND->isAnonymousNamespace())
-        return true;
+    if (const auto *ND = dyn_cast<NamespaceDecl>(DC);
+        ND && ND->isAnonymousNamespace())
+      return true;
   }
 
   return false;
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index 3120c5c6c86d5..231198a8ccd32 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -69,9 +69,9 @@ void InlineFunctionDeclCheck::check(const 
MatchFinder::MatchResult &Result) {
     return;
 
   // Ignore lambda functions as they are internal and implicit.
-  if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl))
-    if (MethodDecl->getParent()->isLambda())
-      return;
+  if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl);
+      MethodDecl && MethodDecl->getParent()->isLambda())
+    return;
 
   // Check if decl starts with LIBC_INLINE
   const auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 2385808ff7a7e..1abe4db743a25 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -255,14 +255,13 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   VariableCategory VC = VariableCategory::Value;
   const QualType VT = Variable->getType();
-  if (VT->isReferenceType()) {
+  if (VT->isReferenceType())
     VC = VariableCategory::Reference;
-  } else if (VT->isPointerType()) {
+  else if (VT->isPointerType())
+    VC = VariableCategory::Pointer;
+  else if (const auto *ArrayT = dyn_cast<ArrayType>(VT);
+           ArrayT && ArrayT->getElementType()->isPointerType())
     VC = VariableCategory::Pointer;
-  } else if (const auto *ArrayT = dyn_cast<ArrayType>(VT)) {
-    if (ArrayT->getElementType()->isPointerType())
-      VC = VariableCategory::Pointer;
-  }
 
   const auto CheckValue = [&]() {
     // Offload const-analysis to utility function.
@@ -339,11 +338,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
     if (WarnPointersAsValues && !VT.isConstQualified())
       CheckValue();
     if (WarnPointersAsPointers) {
-      if (const auto *PT = dyn_cast<PointerType>(VT)) {
-        if (!PT->getPointeeType().isConstQualified() &&
-            !PT->getPointeeType()->isFunctionType())
-          CheckPointee();
-      }
+      if (const auto *PT = dyn_cast<PointerType>(VT);
+          PT && !PT->getPointeeType().isConstQualified() &&
+          !PT->getPointeeType()->isFunctionType())
+        CheckPointee();
+
       if (const auto *AT = dyn_cast<ArrayType>(VT)) {
         assert(AT->getElementType()->isPointerType());
         if (!AT->getElementType()->getPointeeType().isConstQualified())
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index adbe8d75ba5aa..beb1c9bc8d3ea 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -67,12 +67,11 @@ AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); 
}
 AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
 
 AST_MATCHER(Decl, isInImportableModuleUnit) {
-  if (const Module *OwningModule = Node.getOwningModule())
-    if (OwningModule->Kind == Module::ModuleInterfaceUnit ||
-        OwningModule->Kind == Module::ModulePartitionInterface ||
-        OwningModule->Kind == Module::ModulePartitionImplementation)
-      return true;
-  return false;
+  const Module *OwningModule = Node.getOwningModule();
+  return OwningModule &&
+         (OwningModule->Kind == Module::ModuleInterfaceUnit ||
+          OwningModule->Kind == Module::ModulePartitionInterface ||
+          OwningModule->Kind == Module::ModulePartitionImplementation);
 }
 
 AST_MATCHER_P(Decl, isAllRedeclsInMainFile, const FileExtensionsSet *,
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index 551ae8b1110bc..3cf0173aaa002 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -181,10 +181,10 @@ initializeBindArgumentForCallExpr(const 
MatchFinder::MatchResult &Result,
 static bool anyDescendantIsLocal(const Stmt *Statement) {
   if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Statement)) {
     const ValueDecl *Decl = DeclRef->getDecl();
-    if (const auto *Var = dyn_cast_or_null<VarDecl>(Decl)) {
-      if (Var->isLocalVarDeclOrParm())
-        return true;
-    }
+    if (const auto *Var = dyn_cast_or_null<VarDecl>(Decl);
+        Var && Var->isLocalVarDeclOrParm())
+      return true;
+
   } else if (isa<CXXThisExpr>(Statement)) {
     return true;
   }
@@ -378,12 +378,10 @@ static void addFunctionCallArgs(ArrayRef<BindArgument> 
Args,
 
 static bool isPlaceHolderIndexRepeated(const ArrayRef<BindArgument> Args) {
   llvm::SmallSet<size_t, 4> PlaceHolderIndices;
-  for (const BindArgument &B : Args) {
-    if (B.PlaceHolderIndex) {
-      if (!PlaceHolderIndices.insert(B.PlaceHolderIndex).second)
-        return true;
-    }
-  }
+  for (const BindArgument &B : Args)
+    if (B.PlaceHolderIndex &&
+        !PlaceHolderIndices.insert(B.PlaceHolderIndex).second)
+      return true;
   return false;
 }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
index 98ca1a46be845..e519a1a60d47c 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
@@ -169,16 +169,15 @@ void AvoidCStyleCastCheck::check(const 
MatchFinder::MatchResult &Result) {
                                DestTypeAsWritten->isRecordType() &&
                                !DestTypeAsWritten->isElaboratedTypeSpecifier();
 
-  if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast) {
-    // Function pointer/reference casts may be needed to resolve ambiguities in
-    // case of overloaded functions, so detection of redundant casts is 
trickier
-    // in this case. Don't emit "redundant cast" warnings for function
-    // pointer/reference types.
-    if (sameTypeAsWritten(SourceTypeAsWritten, DestTypeAsWritten)) {
-      diag(CastExpr->getBeginLoc(), "redundant cast to the same type")
-          << FixItHint::CreateRemoval(ReplaceRange);
-      return;
-    }
+  // Function pointer/reference casts may be needed to resolve ambiguities in
+  // case of overloaded functions, so detection of redundant casts is trickier
+  // in this case. Don't emit "redundant cast" warnings for function
+  // pointer/reference types.
+  if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast &&
+      sameTypeAsWritten(SourceTypeAsWritten, DestTypeAsWritten)) {
+    diag(CastExpr->getBeginLoc(), "redundant cast to the same type")
+        << FixItHint::CreateRemoval(ReplaceRange);
+    return;
   }
 
   // The rest of this check is only relevant to C++.
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6965569e6b87e..75bf2a7325900 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -501,13 +501,14 @@ static bool canBeModified(ASTContext *Context, const Expr 
*E) {
   const auto Parents = Context->getParents(*E);
   if (Parents.size() != 1)
     return true;
-  if (const auto *Cast = Parents[0].get<ImplicitCastExpr>()) {
-    if ((Cast->getCastKind() == CK_NoOp &&
-         ASTContext::hasSameType(Cast->getType(), E->getType().withConst())) ||
-        (Cast->getCastKind() == CK_LValueToRValue &&
-         !Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
-      return false;
-  }
+  if (const auto *Cast = Parents[0].get<ImplicitCastExpr>();
+      Cast &&
+      ((Cast->getCastKind() == CK_NoOp &&
+        ASTContext::hasSameType(Cast->getType(), E->getType().withConst())) ||
+       (Cast->getCastKind() == CK_LValueToRValue && !Cast->getType().isNull() 
&&
+        Cast->getType()->isFundamentalType())))
+    return false;
+
   // FIXME: Make this function more generic.
   return true;
 }
@@ -755,7 +756,8 @@ void LoopConvertCheck::doConversion(
                      Parents[0].getSourceRange().getBegin()))) {
               Range = Paren->getSourceRange();
             }
-          } else if (const auto *UOP = Parents[0].get<UnaryOperator>()) {
+          } else if (const auto *UOP = Parents[0].get<UnaryOperator>();
+                     UOP && UOP->getOpcode() == UO_AddrOf) {
             // If we are taking the address of the loop variable, then we must
             // not use a copy, as it would mean taking the address of the 
loop's
             // local index instead.
@@ -763,8 +765,7 @@ void LoopConvertCheck::doConversion(
             // of the loop's body (for instance, in a function that got the
             // loop's index as a const reference parameter), or where we take
             // the address of a member (like "&Arr[i].A.B.C").
-            if (UOP->getOpcode() == UO_AddrOf)
-              CanCopy = false;
+            CanCopy = false;
           }
         }
       } else {
@@ -851,9 +852,9 @@ StringRef LoopConvertCheck::getContainerString(ASTContext 
*Context,
   } else {
     // For CXXOperatorCallExpr such as vector_ptr->size() we want the class
     // object vector_ptr, but for vector[2] we need the whole expression.
-    if (const auto *E = dyn_cast<CXXOperatorCallExpr>(ContainerExpr))
-      if (E->getOperator() != OO_Subscript)
-        ContainerExpr = E->getArg(0);
+    if (const auto *E = dyn_cast<CXXOperatorCallExpr>(ContainerExpr);
+        E && E->getOperator() != OO_Subscript)
+      ContainerExpr = E->getArg(0);
     ContainerString =
         getStringFromRange(Context->getSourceManager(), Context->getLangOpts(),
                            ContainerExpr->getSourceRange());
@@ -991,11 +992,11 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
       return false;
 
   } else if (FixerKind == LFK_PseudoArray) {
-    if (const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(EndCallName)) 
{
+    if (const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(EndCallName);
+        EndCall && !isa<MemberExpr>(EndCall->getCallee()))
       // This call is required to obtain the container.
-      if (!isa<MemberExpr>(EndCall->getCallee()))
-        return false;
-    }
+      return false;
+
     return Nodes.getNodeAs<CallExpr>(EndCallName) != nullptr;
   }
   return true;
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index da86ecf6395ae..d64f71cf35cac 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -139,12 +139,12 @@ bool DeclFinderASTVisitor::VisitTypeLoc(TypeLoc TL) {
   // Check for base type conflicts. For example, when a struct is being
   // referenced in the body of the loop, the above getAsString() will return 
the
   // whole type (ex. "struct s"), but will be caught here.
-  if (const IdentifierInfo *Ident = QType.getBaseTypeIdentifier()) {
-    if (Ident->getName() == Name) {
-      Found = true;
-      return false;
-    }
+  if (const IdentifierInfo *Ident = QType.getBaseTypeIdentifier();
+      Ident && Ident->getName() == Name) {
+    Found = true;
+    return false;
   }
+
   return true;
 }
 
@@ -179,9 +179,9 @@ const Expr *digThroughConstructorsConversions(const Expr 
*E) {
   }
   // If this is a conversion (as iterators commonly convert into their const
   // iterator counterparts), dig through that as well.
-  if (const auto *ME = dyn_cast<CXXMemberCallExpr>(E))
-    if (isa<CXXConversionDecl>(ME->getMethodDecl()))
-      return 
digThroughConstructorsConversions(ME->getImplicitObjectArgument());
+  if (const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
+      ME && isa<CXXConversionDecl>(ME->getMethodDecl()))
+    return digThroughConstructorsConversions(ME->getImplicitObjectArgument());
   return E;
 }
 
@@ -289,10 +289,11 @@ static bool isIndexInSubscriptExpr(const ASTContext 
*Context,
                   Obj->IgnoreParenImpCasts()))
     return true;
 
-  if (const Expr *InnerObj = getDereferenceOperand(Obj->IgnoreParenImpCasts()))
-    if (PermitDeref && areSameExpr(Context, SourceExpr->IgnoreParenImpCasts(),
-                                   InnerObj->IgnoreParenImpCasts()))
-      return true;
+  if (const Expr *InnerObj = getDereferenceOperand(Obj->IgnoreParenImpCasts());
+      InnerObj && PermitDeref &&
+      areSameExpr(Context, SourceExpr->IgnoreParenImpCasts(),
+                  InnerObj->IgnoreParenImpCasts()))
+    return true;
 
   return false;
 }
@@ -536,21 +537,21 @@ bool 
ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
   const Expr *ResultExpr = Member;
   QualType ExprType;
   if (const auto *Call =
-          dyn_cast<CXXOperatorCallExpr>(Base->IgnoreParenImpCasts())) {
-    // If operator->() is a MemberExpr containing a CXXOperatorCallExpr, then
-    // the MemberExpr does not have the expression we want. We therefore catch
-    // that instance here.
-    // For example, if vector<Foo>::iterator defines operator->(), then the
-    // example `i->bar()` at the top of this function is a CXXMemberCallExpr
-    // referring to `i->` as the member function called. We want just `i`, so
-    // we take the argument to operator->() as the base object.
-    if (Call->getOperator() == OO_Arrow) {
-      assert(Call->getNumArgs() == 1 &&
-             "Operator-> takes more than one argument");
-      Obj = getDeclRef(Call->getArg(0));
-      ResultExpr = Obj;
-      ExprType = Call->getCallReturnType(*Context);
-    }
+          dyn_cast<CXXOperatorCallExpr>(Base->IgnoreParenImpCasts());
+      Call && Call->getOperator() == OO_Arrow)
+  // If operator->() is a MemberExpr containing a CXXOperatorCallExpr, then
+  // the MemberExpr does not have the expression we want. We therefore catch
+  // that instance here.
+  // For example, if vector<Foo>::iterator defines operator->(), then the
+  // example `i->bar()` at the top of this function is a CXXMemberCallExpr
+  // referring to `i->` as the member function called. We want just `i`, so
+  // we take the argument to operator->() as the base object.
+  {
+    assert(Call->getNumArgs() == 1 &&
+           "Operator-> takes more than one argument");
+    Obj = getDeclRef(Call->getArg(0));
+    ResultExpr = Obj;
+    ExprType = Call->getCallReturnType(*Context);
   }
 
   if (Obj && exprReferencesVariable(IndexVar, Obj)) {
@@ -600,13 +601,12 @@ bool ForLoopIndexUseVisitor::TraverseCXXMemberCallExpr(
   // this is restricted to pseudo-arrays by requiring a single, integer
   // argument.
   const IdentifierInfo *Ident = Member->getMemberDecl()->getIdentifier();
-  if (Ident && Ident->isStr("at") && MemberCall->getNumArgs() == 1) {
-    if (isIndexInSubscriptExpr(Context, MemberCall->getArg(0), IndexVar,
-                               Member->getBase(), ContainerExpr,
-                               ContainerNeedsDereference)) {
-      addUsage(Usage(MemberCall));
-      return true;
-    }
+  if (Ident && Ident->isStr("at") && MemberCall->getNumArgs() == 1 &&
+      isIndexInSubscriptExpr(Context, MemberCall->getArg(0), IndexVar,
+                             Member->getBase(), ContainerExpr,
+                             ContainerNeedsDereference)) {
+    addUsage(Usage(MemberCall));
+    return true;
   }
 
   if (containsExpr(Context, &DependentExprs, Member->getBase()))
@@ -828,12 +828,12 @@ bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
   // traversal so that we don't end up diagnosing the contained DeclRefExpr as
   // inconsistent usage. No need to record the usage here -- this is done in
   // TraverseLambdaCapture().
-  if (const auto *LE = dyn_cast_or_null<LambdaExpr>(NextStmtParent)) {
+  if (const auto *LE = dyn_cast_or_null<LambdaExpr>(NextStmtParent);
+      LE && S != LE->getBody())
     // Any child of a LambdaExpr that isn't the body is an initialization
     // expression.
-    if (S != LE->getBody())
-      return true;
-  }
+    return true;
+
   return traverseStmtImpl(S);
 }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
index 3c25dd7bd3aa2..bef2e3cca57a7 100644
--- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -542,11 +542,11 @@ void MacroToEnumCheck::check(
     return;
 
   SourceRange Range = TLDecl->getSourceRange();
-  if (auto *TemplateFn = Result.Nodes.getNodeAs<FunctionTemplateDecl>("top")) {
-    if (TemplateFn->isThisDeclarationADefinition() && TemplateFn->hasBody())
-      Range = SourceRange{TemplateFn->getBeginLoc(),
-                          TemplateFn->getUnderlyingDecl()->getBodyRBrace()};
-  }
+  if (auto *TemplateFn = Result.Nodes.getNodeAs<FunctionTemplateDecl>("top");
+      TemplateFn && TemplateFn->isThisDeclarationADefinition() &&
+      TemplateFn->hasBody())
+    Range = SourceRange{TemplateFn->getBeginLoc(),
+                        TemplateFn->getUnderlyingDecl()->getBodyRBrace()};
 
   if (isValid(Range) && !empty(Range))
     PPCallback->invalidateRange(Range);
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index a2a98111be3f8..c05df597a28a4 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -347,10 +347,10 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder 
&Diag,
     //   std::make_smart_ptr<S>(std::initializer_list<int>({}), 1);
     //   std::make_smart_ptr<S2>(std::vector<int>({1}));
     //   std::make_smart_ptr<S3>(S2{1, 2}, 3);
-    if (const auto *CE = New->getConstructExpr()) {
-      if (HasListInitializedArgument(CE))
-        return false;
-    }
+    if (const auto *CE = New->getConstructExpr();
+        CE && HasListInitializedArgument(CE))
+      return false;
+
     if (ArraySizeExpr.empty()) {
       const SourceRange InitRange = New->getDirectInitRange();
       Diag << FixItHint::CreateRemoval(
@@ -406,14 +406,14 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder 
&Diag,
       // Pair. If we found any invisible or deleted copy/move constructor, we
       // stop generating fixes -- as the C++ rule is complicated and we are 
less
       // certain about the correct fixes.
-      if (const CXXRecordDecl *RD = New->getType()->getPointeeCXXRecordDecl()) 
{
-        if (llvm::any_of(RD->ctors(), [](const CXXConstructorDecl *Ctor) {
-              return Ctor->isCopyOrMoveConstructor() &&
-                     (Ctor->isDeleted() || Ctor->getAccess() == AS_private);
-            })) {
-          return false;
-        }
+      if (const CXXRecordDecl *RD = New->getType()->getPointeeCXXRecordDecl();
+          RD && llvm::any_of(RD->ctors(), [](const CXXConstructorDecl *Ctor) {
+            return Ctor->isCopyOrMoveConstructor() &&
+                   (Ctor->isDeleted() || Ctor->getAccess() == AS_private);
+          })) {
+        return false;
       }
+
       InitRange = SourceRange(
           New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
           New->getInitializer()->getSourceRange().getEnd());
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index d1f0b16c26468..20166f419aa4e 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -115,15 +115,15 @@ static bool paramReferredExactlyOnce(const 
CXXConstructorDecl *Ctor,
     ///
     /// Stops the AST traversal if more than one usage is found.
     bool VisitDeclRefExpr(DeclRefExpr *D) {
-      if (const ParmVarDecl *To = dyn_cast<ParmVarDecl>(D->getDecl())) {
-        if (To == ParamDecl) {
-          ++Count;
-          if (Count > 1U) {
-            // No need to look further, used more than once.
-            return false;
-          }
+      if (const ParmVarDecl *To = dyn_cast<ParmVarDecl>(D->getDecl());
+          To && To == ParamDecl) {
+        ++Count;
+        if (Count > 1U) {
+          // No need to look further, used more than once.
+          return false;
         }
       }
+
       return true;
     }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index af6f108006d16..49e21e8e57ce0 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -292,10 +292,10 @@ void TypeTraitsCheck::check(const 
MatchFinder::MatchResult &Result) {
     if (!DRE->hasQualifier())
       return;
     if (const auto *CTSD = 
dyn_cast_if_present<ClassTemplateSpecializationDecl>(
-            DRE->getQualifier().getAsRecordDecl())) {
-      if (isNamedDeclInStdTraitsSet(CTSD, ValueTraits))
-        EmitValueWarning(DRE->getQualifierLoc(), DRE->getEndLoc());
-    }
+            DRE->getQualifier().getAsRecordDecl());
+        CTSD && isNamedDeclInStdTraitsSet(CTSD, ValueTraits))
+      EmitValueWarning(DRE->getQualifierLoc(), DRE->getEndLoc());
+
     return;
   }
 
@@ -303,11 +303,11 @@ void TypeTraitsCheck::check(const 
MatchFinder::MatchResult &Result) {
     const NestedNameSpecifierLoc QualLoc = TL->getQualifierLoc();
     const NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
     if (const auto *CTSD = 
dyn_cast_if_present<ClassTemplateSpecializationDecl>(
-            NNS.getAsRecordDecl())) {
-      if (isNamedDeclInStdTraitsSet(CTSD, TypeTraits))
-        EmitTypeWarning(TL->getQualifierLoc(), TL->getEndLoc(),
-                        TL->getElaboratedKeywordLoc());
-    }
+            NNS.getAsRecordDecl());
+        CTSD && isNamedDeclInStdTraitsSet(CTSD, TypeTraits))
+      EmitTypeWarning(TL->getQualifierLoc(), TL->getEndLoc(),
+                      TL->getElaboratedKeywordLoc());
+
     return;
   }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index ca93f01e2ef9c..6c873e3f80004 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -308,14 +308,15 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, 
ASTContext *Context) {
       return;
     }
 
-    if (const auto *NestedConstruct = dyn_cast<CXXConstructExpr>(E)) {
+    if (const auto *NestedConstruct = dyn_cast<CXXConstructExpr>(E);
+        NestedConstruct &&
+        NestedConstruct->getConstructor()->isConvertingConstructor(false)) {
       // If we ran into an implicit conversion constructor, can't convert.
       //
       // FIXME: The following only checks if the constructor can be used
       // implicitly, not if it actually was. Cases where the converting
       // constructor was used explicitly won't get converted.
-      if (NestedConstruct->getConstructor()->isConvertingConstructor(false))
-        return;
+      return;
     }
     if (!ASTContext::hasSameType(V->getType(), E->getType()))
       return;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index 4dc78904f8bb5..093f40afb39a0 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -186,16 +186,13 @@ matchTrailingTemplateParam(const FunctionTemplateDecl 
*FunctionTemplate) {
                 LastTemplateParam->getTypeSourceInfo()->getTypeLoc()),
             LastTemplateParam};
   }
-  if (const auto *LastTemplateParam =
-          dyn_cast<TemplateTypeParmDecl>(LastParam)) {
-    if (LastTemplateParam->hasDefaultArgument() &&
-        LastTemplateParam->getIdentifier() == nullptr) {
-      return {
-          matchEnableIfSpecialization(LastTemplateParam->getDefaultArgument()
-                                          .getTypeSourceInfo()
-                                          ->getTypeLoc()),
-          LastTemplateParam};
-    }
+  if (const auto *LastTemplateParam = 
dyn_cast<TemplateTypeParmDecl>(LastParam);
+      LastTemplateParam && LastTemplateParam->hasDefaultArgument() &&
+      LastTemplateParam->getIdentifier() == nullptr) {
+    return {matchEnableIfSpecialization(LastTemplateParam->getDefaultArgument()
+                                            .getTypeSourceInfo()
+                                            ->getTypeLoc()),
+            LastTemplateParam};
   }
   return {};
 }
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index abcca3365d172..ddee0080014b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -78,11 +78,11 @@ static const DeclRefExpr *findFirstNonVisibleDeclRef(const 
Stmt *S,
   if (!S)
     return nullptr;
 
-  if (const auto *DRE = dyn_cast<DeclRefExpr>(S)) {
-    if (!isVisibleFromDefaultMemberInitializer(DRE->getDecl(), Field, SM) ||
-        !isVisibleFromDefaultMemberInitializer(DRE->getFoundDecl(), Field, SM))
-      return DRE;
-  }
+  if (const auto *DRE = dyn_cast<DeclRefExpr>(S);
+      DRE &&
+      (!isVisibleFromDefaultMemberInitializer(DRE->getDecl(), Field, SM) ||
+       !isVisibleFromDefaultMemberInitializer(DRE->getFoundDecl(), Field, SM)))
+    return DRE;
 
   for (const Stmt *Child : S->children())
     if (const auto *DRE = findFirstNonVisibleDeclRef(Child, Field, SM))
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
index f0466852ef5c3..651fb98101ff2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -21,10 +21,10 @@ AST_MATCHER(FunctionDecl, hasAnyDefinition) {
       Node.isDeleted())
     return true;
 
-  if (const FunctionDecl *Definition = Node.getDefinition())
-    if (Definition->hasBody() || Definition->isPureVirtual() ||
-        Definition->isDefaulted() || Definition->isDeleted())
-      return true;
+  if (const FunctionDecl *Definition = Node.getDefinition();
+      Definition && (Definition->hasBody() || Definition->isPureVirtual() ||
+                     Definition->isDefaulted() || Definition->isDeleted()))
+    return true;
 
   return false;
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index f1f42aac25e2a..4f561a1f10204 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -470,12 +470,11 @@ class CastSequenceVisitor : public 
RecursiveASTVisitor<CastSequenceVisitor> {
 
       // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
       // them and keep going up.
-      if (Loc.isValid()) {
-        if (!expandsFrom(Loc, MacroLoc)) {
-          Result = Parent;
-          return true;
-        }
+      if (Loc.isValid() && !expandsFrom(Loc, MacroLoc)) {
+        Result = Parent;
+        return true;
       }
+
       Start = Parent;
     }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to