[clang] [clang-tools-extra] [clang][Sema] Respect const-qualification of methods in heuristic results (PR #123551)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 00:02:01 PST 2025


================
@@ -422,7 +425,15 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
     if (!RD->hasDefinition())
       return {};
     RD = RD->getDefinition();
-    return lookupDependentName(RD, Name, Filter);
+    return lookupDependentName(RD, Name, [&](const NamedDecl *ND) {
+      if (!Filter(ND))
+        return false;
+      if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) {
+        if (QT.isConstQualified() && !MD->isConst())
+          return false;
----------------
HighCommander4 wrote:

Thanks for the suggestion!

After some poking around I found `Qualifiers::compatiblyIncludes()` which seems to fit the purpose and is used in a number of similar situations (e.g. in [`checkPointerTypesForAssignment()`](https://searchfox.org/llvm/rev/af91372b75613d5654e68d393477e8621cb93da7/clang/lib/Sema/SemaExpr.cpp#8944)).

https://github.com/llvm/llvm-project/pull/123551


More information about the cfe-commits mailing list