llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)

<details>
<summary>Changes</summary>



---

Patch is 32.14 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/213959.diff


20 Files Affected:

- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp 
(+4-6) 
- (modified) clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp 
(+13-15) 
- (modified) 
clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp (+4-4) 
- (modified) 
clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp 
(+3-3) 
- (modified) clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp 
(+3-3) 
- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
(+10-11) 
- (modified) clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
(+5-6) 
- (modified) clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp (+8-10) 
- (modified) clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp 
(+9-10) 
- (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
(+18-17) 
- (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
(+38-38) 
- (modified) clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp (+5-5) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+11-11) 
- (modified) clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp (+7-7) 
- (modified) clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp (+9-9) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp (+4-3) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp 
(+7-10) 
- (modified) 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp (+5-5) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp 
(+4-4) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp (+4-5) 


``````````diff
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(...
[truncated]

``````````

</details>


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

Reply via email to