-
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 6 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 { | ||
|
|
||
|
|
@@ -255,6 +256,21 @@ QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E, | |
| } | ||
| } | ||
| } | ||
| // check if member expr is in the context of an explicit object method | ||
| if (!T.Type.isNull() && | ||
| (T.Type->isUndeducedAutoType() || T.Type->isTemplateTypeParmType())) { | ||
| if (auto *DRE = dyn_cast_if_present<DeclRefExpr>(T.E)) { | ||
| auto *PrDecl = dyn_cast_if_present<ParmVarDecl>(DRE->getDecl()); | ||
| // Then the type of 'this' should be type of the record the method is | ||
|
||
| // defined in | ||
| if (PrDecl && PrDecl->isExplicitObjectParameter()) { | ||
| const auto *Parent = | ||
| dyn_cast<TypeDecl>(PrDecl->getDeclContext()->getParent()); | ||
| return {Ctx.getTypeDeclType(Parent)}; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return T; | ||
| }; | ||
| // As an additional protection against infinite loops, bound the number of | ||
|
|
@@ -305,6 +321,14 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr( | |
| Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase(); | ||
| QualType BaseType = ME->getBaseType(); | ||
| BaseType = simplifyType(BaseType, Base, ME->isArrow()); | ||
|
|
||
| // fflush(stdout); | ||
|
||
| // fflush(stderr); | ||
| // std::flush(std::cout); | ||
| // std::flush(std::cerr); | ||
| // using namespace std::chrono_literals; | ||
| // std::this_thread::sleep_for(10ms); | ||
|
|
||
| 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.
I would reword / expand on this as:
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.
Thanks!