-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well #132576
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
Conversation
@llvm/pr-subscribers-clangd @llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) ChangesFull diff: https://github.com/llvm/llvm-project/pull/132576.diff 3 Files Affected:
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e12d7691c58fb..693e965e78a96 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
)objc",
R"cpp(
struct PointerIntPairInfo {
- static void *getPointer(void *Value);
+ static void *$decl[[getPointer]](void *Value);
};
template <typename Info = PointerIntPairInfo> struct PointerIntPair {
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..5f1495f5334b9 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -300,9 +300,9 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr(
std::vector<const NamedDecl *>
HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) {
- return resolveDependentMember(
- resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
- StaticFilter);
+ QualType Qualifier = resolveNestedNameSpecifierToType(RE->getQualifier());
+ Qualifier = simplifyType(Qualifier, nullptr, /*UnwrapPointer=*/false);
+ return resolveDependentMember(Qualifier, RE->getDeclName(), StaticFilter);
}
std::vector<const NamedDecl *>
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..b4994c315b2ff 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -429,6 +429,23 @@ TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
cxxMethodDecl(hasName("bar")).bind("output"));
}
+TEST(HeuristicResolver, DeclRefExpr_DefaultTemplateArgument) {
+ std::string Code = R"cpp(
+ struct Default {
+ static void foo();
+ };
+ template <typename T = Default>
+ void bar() {
+ T::foo();
+ }
+ )cpp";
+ // Test resolution of "foo" in "T::foo()".
+ expectResolution(
+ Code, &HeuristicResolver::resolveDeclRefExpr,
+ dependentScopeDeclRefExpr(hasDependentName("foo")).bind("input"),
+ cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
TEST(HeuristicResolver, DeclRefExpr_StaticOverloads) {
std::string Code = R"cpp(
template <typename T>
|
9aff609
to
16dfb5f
Compare
ea94986
to
2c9fc17
Compare
(Rebased) |
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 for following up on it, this looks great.
Please flesh out the PR body before you commit, with the reason you said in #132576 (comment).
(Just a copy-paste is good enough)
(I'm holding off on merging this until #130473 is merged first. There isn't an actual code dependency, it just simplifies the version control workflow to merge things in the order in which I have them stacked locally.) |
16dfb5f
to
3884509
Compare
…eDeclRefExpr as well
787f795
to
ac3780d
Compare
(Rebased) |
…eDeclRefExpr as well (llvm#132576) This is a follow-up to llvm#131074. After moving the default argument heuristic to `simplifyType` in that patch, the heuristic no longer applied to the `DependentScopeDeclRefExpr` case, because that wasn't using `simplifyType`. This patch fixes that, with an added testcase.
This is a follow-up to #131074. After moving the default argument heuristic to
simplifyType
as per this discussion, I realized that this made it no longer apply to theDependentScopeDeclRefExpr
case, because that wasn't usingsimplifyType
.This patch fixes that, with an added testcase.