================
@@ -301,10 +302,34 @@ std::vector<const NamedDecl *> 
HeuristicResolverImpl::resolveMemberExpr(
     return {};
   }
 
+  // check if member expr is in the context of an explicit object method
+  // If so, it's safe to assume the templated arg is of type of the record
+  const auto ExplicitMemberHeuristic = [&](const Expr *Base) -> QualType {
+    if (auto *DeclRef = dyn_cast_if_present<DeclRefExpr>(Base)) {
+      auto *PrDecl = dyn_cast_if_present<ParmVarDecl>(DeclRef->getDecl());
+
+      if (PrDecl && PrDecl->isExplicitObjectParameter()) {
+        // get the parent, a cxxrecord
+        return Ctx.getTypeDeclType(
+            dyn_cast<TypeDecl>(PrDecl->getDeclContext()->getParent()));
+      }
+    }
+
+    return {};
+  };
+
   // Try resolving the member inside the expression's base type.
   Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase();
   QualType BaseType = ME->getBaseType();
   BaseType = simplifyType(BaseType, Base, ME->isArrow());
+
+  if (!BaseType.isNull() &&
----------------
HighCommander4 wrote:

Can we move this into `simplifyType` itself? Specifically, inside 
[`SimplifyOneStep`](https://searchfox.org/llvm/rev/feac561478bbdbc28a4fe22ba070e27a3a495ffb/clang/lib/Sema/HeuristicResolver.cpp#208),
 what are `BaseType` and `Base` here are available as `T.Type` and `T.Expr` 
respectively.

That would make this heuristic a bit more general. (For example, in combination 
with [this patch](https://github.com/llvm/llvm-project/pull/151643) which adds 
a `simplifyType` call site in `SemaCodeComplete`, it gets code completion to 
work after `self.^` in such a function.)

https://github.com/llvm/llvm-project/pull/155143
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to