Skip to content

Commit fa0498f

Browse files
[clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (#132576)
This is a follow-up to #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.
1 parent 0816c7a commit fa0498f

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
10911091
)objc",
10921092
R"cpp(
10931093
struct PointerIntPairInfo {
1094-
static void *getPointer(void *Value);
1094+
static void *$decl[[getPointer]](void *Value);
10951095
};
10961096
10971097
template <typename Info = PointerIntPairInfo> struct PointerIntPair {

clang/lib/Sema/HeuristicResolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr(
315315

316316
std::vector<const NamedDecl *>
317317
HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) {
318-
return resolveDependentMember(
319-
resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
320-
StaticFilter);
318+
QualType Qualifier = resolveNestedNameSpecifierToType(RE->getQualifier());
319+
Qualifier = simplifyType(Qualifier, nullptr, /*UnwrapPointer=*/false);
320+
return resolveDependentMember(Qualifier, RE->getDeclName(), StaticFilter);
321321
}
322322

323323
std::vector<const NamedDecl *>

clang/unittests/Sema/HeuristicResolverTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,23 @@ TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
463463
cxxMethodDecl(hasName("bar")).bind("output"));
464464
}
465465

466+
TEST(HeuristicResolver, DeclRefExpr_DefaultTemplateArgument) {
467+
std::string Code = R"cpp(
468+
struct Default {
469+
static void foo();
470+
};
471+
template <typename T = Default>
472+
void bar() {
473+
T::foo();
474+
}
475+
)cpp";
476+
// Test resolution of "foo" in "T::foo()".
477+
expectResolution(
478+
Code, &HeuristicResolver::resolveDeclRefExpr,
479+
dependentScopeDeclRefExpr(hasDependentName("foo")).bind("input"),
480+
cxxMethodDecl(hasName("foo")).bind("output"));
481+
}
482+
466483
TEST(HeuristicResolver, DeclRefExpr_StaticOverloads) {
467484
std::string Code = R"cpp(
468485
template <typename T>

0 commit comments

Comments
 (0)