================
@@ -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
+  // parameter T, which has no default argument to fall back on, and nothing
+  // else says what T will be. This is the member-typedef analogue of
+  // `std::vector<T>::value_type`.
+  expectResolution(
+      Code, &HeuristicResolver::resolveMemberExpr,
+      cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"));
+}
+
+TEST(HeuristicResolver, MemberExpr_CallOfUsingDeclFromDependentBase) {
+  std::string Code = R"cpp(
+    struct Result {
+      void foo();
+    };
+    template <typename T>
+    struct Base {
+      Result get();
+    };
+    template <typename T>
+    struct Derived : Base<T> {
+      typedef Base<T> _Base;
+      using _Base::get;
+    };
+    template <typename T>
+    void bar(Derived<T> d) {
+      d.get().foo();
+    }
+  )cpp";
+  // Test resolution of "foo" in "d.get().foo()", where "get" is found as a
+  // using declaration naming a member of a dependent base class.
+  expectResolution(
+      Code, &HeuristicResolver::resolveMemberExpr,
+      cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+      cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgumentNotSeenByBase) {
+  std::string Code = R"cpp(
+    struct Result {
+      void foo();
+    };
+    template <typename T, typename A>
+    struct Base {
+      typedef A type;
+      type get();
+    };
+    template <typename T, typename A = Result>
+    struct Derived : Base<T, A> {
+      typedef Base<T, A> _Base;
+      using _Base::get;
+    };
+    template <typename T>
+    void bar(Derived<T> d) {
+      d.get().foo();
+    }
+  )cpp";
+  // Test that "foo" in "d.get().foo()" does not resolve. Looking "get" up in
----------------
HighCommander4 wrote:

For test cases which are testing that something does not resolve, we should 
make it clear whether it's "does not resolve and that's good; resolving would 
be incorrect", vs. "does not resolve due to limitations of the current 
implementation, but would be nice to get it to resolve". This one seems like 
the latter; please add a "FIXME" or something to suggest that.

https://github.com/llvm/llvm-project/pull/223667
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to