[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)
Nathan Ridge via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Mar 22 18:17:18 PDT 2025
https://github.com/HighCommander4 updated https://github.com/llvm/llvm-project/pull/132576
>From 2c9fc17bf2ef28c42df472598e4b7d09297cb668 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Sat, 22 Mar 2025 20:54:02 -0400
Subject: [PATCH] [clang][HeuristicResolver] Apply default argument heuristic
in resolveDeclRefExpr as well
---
.../clangd/unittests/XRefsTests.cpp | 2 +-
clang/lib/Sema/HeuristicResolver.cpp | 6 +++---
clang/unittests/Sema/HeuristicResolverTest.cpp | 17 +++++++++++++++++
3 files changed, 21 insertions(+), 4 deletions(-)
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 9b793e876a49f..5202ae340bbfd 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -315,9 +315,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 f7eb4b23c2ab0..3ed6bba790be3 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -463,6 +463,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>
More information about the llvm-branch-commits
mailing list