Skip to content

Commit aec579f

Browse files
Respect const-qualification on methods in resolveDependentMember()
1 parent cd87f05 commit aec579f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/lib/Sema/HeuristicResolver.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,15 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
425425
if (!RD->hasDefinition())
426426
return {};
427427
RD = RD->getDefinition();
428-
return lookupDependentName(RD, Name, Filter);
428+
return lookupDependentName(RD, Name, [&](const NamedDecl *ND) {
429+
if (!Filter(ND))
430+
return false;
431+
if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) {
432+
return MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
433+
Ctx);
434+
}
435+
return true;
436+
});
429437
}
430438
return {};
431439
}

clang/unittests/Sema/HeuristicResolverTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ TEST(HeuristicResolver, MemberExpr_SmartPointer) {
135135
cxxMethodDecl(hasName("foo")).bind("output"));
136136
}
137137

138+
TEST(HeuristicResolver, MemberExpr_SmartPointer_Qualified) {
139+
std::string Code = R"cpp(
140+
template <typename> struct Waldo {
141+
void find();
142+
void find() const;
143+
};
144+
template <typename T> struct unique_ptr {
145+
T* operator->();
146+
};
147+
template <typename T>
148+
void test(unique_ptr<const Waldo<T>>& w) {
149+
w->find();
150+
}
151+
)cpp";
152+
expectResolution(
153+
Code, &HeuristicResolver::resolveMemberExpr,
154+
cxxDependentScopeMemberExpr(hasMemberName("find")).bind("input"),
155+
cxxMethodDecl(hasName("find"), isConst()).bind("output"));
156+
}
157+
138158
TEST(HeuristicResolver, MemberExpr_Chained) {
139159
std::string Code = R"cpp(
140160
struct A { void foo() {} };

0 commit comments

Comments
 (0)