nridge created this revision.
nridge added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
https://github.com/llvm/llvm-project/issues/64841
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158873
Files:
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
void play(Dog *dog) {
[dog ho^wl];
}
- )objc"};
+ )objc",
+ R"cpp(
+ struct PointerIntPairInfo {
+ static void *getPointer(void *Value);
+ };
+
+ template <typename Info = PointerIntPairInfo> struct PointerIntPair {
+ void *Value;
+ void *getPointer() const { return Info::get^Pointer(Value); }
+ };
+ )cpp"};
for (const char *Test : Tests) {
Annotations T(Test);
std::optional<Range> WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===================================================================
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
std::vector<const NamedDecl *> HeuristicResolver::resolveMemberExpr(
const CXXDependentScopeMemberExpr *ME) const {
- // If the expression has a qualifier, first try resolving the member
- // inside the qualifier's type.
+ // If the expression has a qualifier, try resolving the member inside the
+ // qualifier's type.
// Note that we cannot use a NonStaticFilter in either case, for a couple
// of reasons:
// 1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,13 @@
if (!Decls.empty())
return Decls;
}
+
+ // Do not proceed to try resolving the member in the expression's base type
+ // without regard to the qualifier, as that could produce incorrect
results.
+ return {};
}
- // If that didn't yield any results, try resolving the member inside
- // the expression's base type.
+ // Try resolving the member inside the expression's base type.
const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
if (ME->isArrow()) {
BaseType = getPointeeType(BaseType);
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
void play(Dog *dog) {
[dog ho^wl];
}
- )objc"};
+ )objc",
+ R"cpp(
+ struct PointerIntPairInfo {
+ static void *getPointer(void *Value);
+ };
+
+ template <typename Info = PointerIntPairInfo> struct PointerIntPair {
+ void *Value;
+ void *getPointer() const { return Info::get^Pointer(Value); }
+ };
+ )cpp"};
for (const char *Test : Tests) {
Annotations T(Test);
std::optional<Range> WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===================================================================
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
std::vector<const NamedDecl *> HeuristicResolver::resolveMemberExpr(
const CXXDependentScopeMemberExpr *ME) const {
- // If the expression has a qualifier, first try resolving the member
- // inside the qualifier's type.
+ // If the expression has a qualifier, try resolving the member inside the
+ // qualifier's type.
// Note that we cannot use a NonStaticFilter in either case, for a couple
// of reasons:
// 1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,13 @@
if (!Decls.empty())
return Decls;
}
+
+ // Do not proceed to try resolving the member in the expression's base type
+ // without regard to the qualifier, as that could produce incorrect results.
+ return {};
}
- // If that didn't yield any results, try resolving the member inside
- // the expression's base type.
+ // Try resolving the member inside the expression's base type.
const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
if (ME->isArrow()) {
BaseType = getPointeeType(BaseType);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits