Skip to content

Commit 2941fa3

Browse files
[clang][HeuristicResolver] Only perform qualifier check for instance methods (#125166)
Fixes #125164
1 parent f8ef269 commit 2941fa3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/Sema/HeuristicResolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
482482
if (!Filter(ND))
483483
return false;
484484
if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) {
485-
return MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
485+
return !MD->isInstance() ||
486+
MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
486487
Ctx);
487488
}
488489
return true;

clang/unittests/Sema/HeuristicResolverTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ TEST(HeuristicResolver, MemberExpr_SmartPointer_Qualified) {
155155
cxxMethodDecl(hasName("find"), isConst()).bind("output"));
156156
}
157157

158+
TEST(HeuristicResolver, MemberExpr_Static_Qualified) {
159+
std::string Code = R"cpp(
160+
template <typename T>
161+
struct Waldo {
162+
static void find();
163+
};
164+
template <typename T>
165+
void foo(const Waldo<T>& t) {
166+
t.find();
167+
}
168+
)cpp";
169+
// Test resolution of "find" in "t.find()".
170+
// The object being `const` should have no bearing on a call to a static
171+
// method.
172+
expectResolution(
173+
Code, &HeuristicResolver::resolveMemberExpr,
174+
cxxDependentScopeMemberExpr(hasMemberName("find")).bind("input"),
175+
cxxMethodDecl(hasName("find")).bind("output"));
176+
}
177+
158178
TEST(HeuristicResolver, MemberExpr_AutoTypeDeduction1) {
159179
std::string Code = R"cpp(
160180
template <typename T>

0 commit comments

Comments
 (0)