[clang] [clang][HeuristicResolver] Resolve more dependent member accesses (PR #223667)
Christian Kandeler via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 24 06:25:11 PDT 2026
================
@@ -580,6 +580,136 @@ TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument_Recursive) {
cxxMethodDecl(hasName("foo")).bind("output"));
}
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument_MemberTypedef) {
+ std::string Code = R"cpp(
+ struct Default {
+ void foo();
+ };
+ template <typename T, typename A = Default>
+ struct S {
+ typedef A type;
+ };
+ template <typename T>
+ void bar() {
+ typename S<T>::type t;
+ t.foo();
+ }
+ )cpp";
+ // Test resolution of "foo" in "t.foo()", where the type of "t" resolves
+ // to the template parameter "A" via the member typedef "type".
+ expectResolution(
+ Code, &HeuristicResolver::resolveMemberExpr,
+ cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+ cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument_ReturnType) {
+ std::string Code = R"cpp(
+ struct Default {
+ void foo();
+ };
+ template <typename T, typename A = Default>
+ struct S {
+ typedef A type;
+ type get();
+ };
+ template <typename T>
+ void bar(S<T> s) {
+ s.get().foo();
+ }
+ )cpp";
+ // Test resolution of "foo" in "s.get().foo()", where the return type of
+ // "get()" resolves to the template parameter "A" via the member typedef
+ // "type".
+ expectResolution(
+ Code, &HeuristicResolver::resolveMemberExpr,
+ cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+ cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
+TEST(HeuristicResolver, MemberExpr_MemberTypedefWithoutDefaultArgument) {
+ std::string Code = R"cpp(
+ template <typename T>
+ struct S {
+ typedef T type;
+ };
+ template <typename T>
+ void bar() {
+ typename S<T>::type t;
+ t.foo();
+ }
+ )cpp";
+ // Test that "foo" in "t.foo()" does not resolve: "S<T>::type" names S's own
----------------
ckandeler wrote:
Done.
https://github.com/llvm/llvm-project/pull/223667
More information about the cfe-commits
mailing list