Recently I've improved fn_type_unification's handling of access checks, but resolve_overloaded_unification didn't get the same attention. Fortunately, it's a simple matter of switching it over to using instantiate_template so that we have a function to check the accesses against.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit 7ac5af72354e0db079763cd65d4683689542bf3d
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Dec 12 17:43:14 2013 -0500

    	PR c++/58954
    	* pt.c (resolve_overloaded_unification): Use instantiate_template.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2c64a71..d566afd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16407,7 +16407,7 @@ resolve_overloaded_unification (tree tparms,
 	  if (subargs != error_mark_node
 	      && !any_dependent_template_arguments_p (subargs))
 	    {
-	      elem = tsubst (TREE_TYPE (fn), subargs, tf_none, NULL_TREE);
+	      elem = TREE_TYPE (instantiate_template (fn, subargs, tf_none));
 	      if (try_one_overload (tparms, targs, tempargs, parm,
 				    elem, strict, sub_strict, addr_p, explain_p)
 		  && (!goodfn || !same_type_p (goodfn, elem)))
diff --git a/gcc/testsuite/g++.dg/cpp0x/access02.C b/gcc/testsuite/g++.dg/cpp0x/access02.C
new file mode 100644
index 0000000..74960a6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/access02.C
@@ -0,0 +1,39 @@
+// PR c++/58954
+// { dg-require-effective-target c++11 }
+
+template<class T>
+T&& declval();
+
+template<class T>
+struct foo_argument
+{
+  template<class Ret, class C, class Arg>
+  static Arg test(Ret (C::*)(Arg));
+
+  typedef decltype(test(&T::template foo<>)) type;
+};
+
+template<class T, class>
+struct dependent { typedef T type; };
+
+template<class T>
+struct base
+{
+  template<class Ignore = void>
+  auto foo(int i) -> decltype(declval<
+    typename dependent<T&, Ignore>::type
+  >().foo_impl(i));
+};
+
+struct derived : base<derived>
+{
+  friend struct base<derived>;
+private:
+  int foo_impl(int i);
+};
+
+int main()
+{
+  foo_argument<derived>::type var = 0;
+  return var;
+}

Reply via email to