llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) <details> <summary>Changes</summary> Partially fixes https://github.com/llvm/llvm-project/issues/124450 --- Full diff: https://github.com/llvm/llvm-project/pull/124451.diff 2 Files Affected: - (modified) clang/lib/Sema/HeuristicResolver.cpp (+2-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..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 { `````````` </details> https://github.com/llvm/llvm-project/pull/124451 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits