[clang] [clang][HeuristicResolver] Only perform qualifier check for instance methods (PR #125166)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 30 20:48:43 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Nathan Ridge (HighCommander4)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/125164
---
Full diff: https://github.com/llvm/llvm-project/pull/125166.diff
2 Files Affected:
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+2-1)
- (modified) clang/unittests/Sema/HeuristicResolverTest.cpp (+20)
``````````diff
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 0c57250e63df2e6..36e5b44b8b12cc1 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -482,7 +482,8 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
if (!Filter(ND))
return false;
if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) {
- return MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
+ return !MD->isInstance() ||
+ MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
Ctx);
}
return true;
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp b/clang/unittests/Sema/HeuristicResolverTest.cpp
index a0deb2d936756af..5c3459dbeb1018b 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -155,6 +155,26 @@ TEST(HeuristicResolver, MemberExpr_SmartPointer_Qualified) {
cxxMethodDecl(hasName("find"), isConst()).bind("output"));
}
+TEST(HeuristicResolver, MemberExpr_Static_Qualified) {
+ std::string Code = R"cpp(
+ template <typename T>
+ struct Waldo {
+ static void find();
+ };
+ template <typename T>
+ void foo(const Waldo<T>& t) {
+ t.find();
+ }
+ )cpp";
+ // Test resolution of "find" in "t.find()".
+ // The object being `const` should have no bearing on a call to a static
+ // method.
+ expectResolution(
+ Code, &HeuristicResolver::resolveMemberExpr,
+ cxxDependentScopeMemberExpr(hasMemberName("find")).bind("input"),
+ cxxMethodDecl(hasName("find")).bind("output"));
+}
+
TEST(HeuristicResolver, MemberExpr_AutoTypeDeduction1) {
std::string Code = R"cpp(
template <typename T>
``````````
</details>
https://github.com/llvm/llvm-project/pull/125166
More information about the cfe-commits
mailing list