diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 14c6037729ffeb920de0a7dd6afb8b94de4feaf0..85fe9b5ab85ffcfc0a033e211f636a0db1f6c8ab 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -9244,8 +9244,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 	}
       else
 	{
-	  tree binfo = TYPE_BINFO (TREE_TYPE (first_arg));
-	  callee = build_baselink (binfo, binfo, fn, NULL_TREE);
+	  callee = build_baselink (cand->conversion_path, cand->access_path,
+				   fn, NULL_TREE);
 	  callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
 			      first_arg, callee, NULL_TREE);
 	}
diff --git a/gcc/testsuite/g++.dg/template/non-dependent24.C b/gcc/testsuite/g++.dg/template/non-dependent24.C
new file mode 100644
index 0000000000000000000000000000000000000000..0ddc75c78eea1f475d1490fc9f5c294a9db003dc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent24.C
@@ -0,0 +1,19 @@
+// PR c++/105758
+
+struct A {
+  void foo(int);
+};
+
+template<class>
+struct Z : A {
+  static Z *z;
+  void bar();
+};
+
+template<class T>
+Z<T> *Z<T>::z;
+
+template<class T>
+void Z<T>::bar() {
+  z->foo(0);
+}