[clang] [clang][Sema] Unwrap reference types in HeuristicResolverImpl::resolveTypeToRecordDecl() (PR #124451)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 25 23:24:25 PST 2025
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/124451
Partially fixes https://github.com/llvm/llvm-project/issues/124450
>From 9c8349f994f8c66f07be79834352fbe25301ef43 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Sun, 26 Jan 2025 02:04:45 -0500
Subject: [PATCH] [clang][Sema] Unwrap reference types in
HeuristicResolverImpl::resolveTypeToRecordDecl()
Partially fixes https://github.com/llvm/llvm-project/issues/124450
---
clang/lib/Sema/HeuristicResolver.cpp | 4 ++--
.../unittests/Sema/HeuristicResolverTest.cpp | 21 +++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index e893afed71d268..6157191bafa6fc 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -133,8 +133,8 @@ TemplateName getReferencedTemplateName(const Type *T) {
CXXRecordDecl *HeuristicResolverImpl::resolveTypeToRecordDecl(const Type *T) {
assert(T);
- // Unwrap type sugar such as type aliases.
- T = T->getCanonicalTypeInternal().getTypePtr();
+ // Unwrap references and type sugar such as type aliases.
+ T = T->getCanonicalTypeInternal().getNonReferenceType().getTypePtr();
if (const auto *DNT = T->getAs<DependentNameType>()) {
T = resolveDeclsToType(resolveDependentNameType(DNT), Ctx)
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp b/clang/unittests/Sema/HeuristicResolverTest.cpp
index 2b775b11719ea7..00e19aecdae0a9 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -213,6 +213,27 @@ TEST(HeuristicResolver, MemberExpr_Chained) {
cxxMethodDecl(hasName("foo")).bind("output"));
}
+TEST(HeuristicResolver, MemberExpr_ReferenceType) {
+ std::string Code = R"cpp(
+ struct B {
+ int waldo;
+ };
+ template <typename T>
+ struct A {
+ B &b;
+ };
+ template <typename T>
+ void foo(A<T> &a) {
+ a.b.waldo;
+ }
+ )cpp";
+ // Test resolution of "waldo" in "a.b.waldo".
+ expectResolution(
+ Code, &HeuristicResolver::resolveMemberExpr,
+ cxxDependentScopeMemberExpr(hasMemberName("waldo")).bind("input"),
+ fieldDecl(hasName("waldo")).bind("output"));
+}
+
TEST(HeuristicResolver, MemberExpr_TemplateArgs) {
std::string Code = R"cpp(
struct Foo {
More information about the cfe-commits
mailing list