-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Heuristic resolution for explicit object parameter #155143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
c1cdb39
0d48289
cd3601a
ea15161
c2b8ac4
bf73e27
b48fa0e
466efd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| #include "clang/AST/TemplateBase.h" | ||
| #include "clang/AST/Type.h" | ||
| #include "llvm/ADT/identity.h" | ||
| #include <optional> | ||
|
|
||
| namespace clang { | ||
|
|
||
|
|
@@ -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() && | ||
|
||
| (BaseType->isUndeducedAutoType() || BaseType->isTemplateTypeParmType())) { | ||
| if (auto Type = ExplicitMemberHeuristic(Base); !Type.isNull()) { | ||
| BaseType = Type; | ||
| } | ||
| } | ||
|
|
||
| return resolveDependentMember(BaseType, ME->getMember(), NoFilter); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a new top-level test case (which involves repeating some boilerplate), could you add an entry to the array in
RenameTest.WithinFileRenameinstead (and adjust the flags of that test to use-std=c++23as necessary)?