[clang] [clang][Sema] Handle dependent qualifier in HeuristicResolver::resolveDeclRefExpr() (PR #124515)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 26 23:16:35 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Nathan Ridge (HighCommander4)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/124515.diff
2 Files Affected:
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+3-2)
- (modified) clang/unittests/Sema/HeuristicResolverTest.cpp (+21)
``````````diff
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index e893afed71d268..87c7274e7aefa6 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -262,8 +262,9 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr(
std::vector<const NamedDecl *>
HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) {
- return resolveDependentMember(QualType(RE->getQualifier()->getAsType(), 0),
- RE->getDeclName(), StaticFilter);
+ return resolveDependentMember(
+ resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
+ StaticFilter);
}
std::vector<const NamedDecl *>
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp b/clang/unittests/Sema/HeuristicResolverTest.cpp
index 2b775b11719ea7..e5cd1254d75422 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -385,6 +385,27 @@ TEST(HeuristicResolver, DeclRefExpr_RespectScope) {
dependentScopeDeclRefExpr(hasDependentName("getPointer")).bind("input"));
}
+TEST(HeuristicResolver, DeclRefExpr_Nested) {
+ std::string Code = R"cpp(
+ struct S {
+ static int Waldo;
+ };
+ template <typename T>
+ struct Meta {
+ using Type = S;
+ };
+ template <typename T>
+ void foo() {
+ Meta<T>::Type::Waldo;
+ }
+ )cpp";
+ // Test resolution of "Waldo" in "Meta<T>::Type::Waldo".
+ expectResolution(
+ Code, &HeuristicResolver::resolveDeclRefExpr,
+ dependentScopeDeclRefExpr(hasDependentName("Waldo")).bind("input"),
+ varDecl(hasName("Waldo")).bind("output"));
+}
+
TEST(HeuristicResolver, DependentNameType) {
std::string Code = R"cpp(
template <typename>
``````````
</details>
https://github.com/llvm/llvm-project/pull/124515
More information about the cfe-commits
mailing list