25c7f1
2016-06-14  Jason Merrill  <jason@redhat.com>
25c7f1
25c7f1
	* call.c (add_function_candidate): Be more careful about
25c7f1
	ref-to-ptr conversion.
25c7f1
25c7f1
2016-06-15  Jakub Jelinek  <jakub@redhat.com>
25c7f1
25c7f1
	* g++.dg/cpp0x/ref-qual17.C: New test.
25c7f1
25c7f1
--- gcc/cp/call.c.jj	2014-08-06 10:45:03.260163142 +0200
25c7f1
+++ gcc/cp/call.c	2016-06-15 11:15:06.663878423 +0200
25c7f1
@@ -1975,7 +1975,9 @@ add_function_candidate (struct z_candida
25c7f1
 		  bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
25c7f1
 		  parmtype = cp_build_reference_type (parmtype, rv);
25c7f1
 		  if (TREE_CODE (arg) == CONVERT_EXPR
25c7f1
-		      && TYPE_PTR_P (TREE_TYPE (arg)))
25c7f1
+		      && TYPE_PTR_P (TREE_TYPE (arg))
25c7f1
+		      && (TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0)))
25c7f1
+			  == REFERENCE_TYPE))
25c7f1
 		    /* Strip conversion from reference to pointer.  */
25c7f1
 		    arg = TREE_OPERAND (arg, 0);
25c7f1
 		  arg = build_fold_indirect_ref (arg);
25c7f1
--- gcc/testsuite/g++.dg/cpp0x/ref-qual17.C.jj	2016-06-15 11:12:57.692558903 +0200
25c7f1
+++ gcc/testsuite/g++.dg/cpp0x/ref-qual17.C	2016-06-15 11:07:02.000000000 +0200
25c7f1
@@ -0,0 +1,12 @@
25c7f1
+// { dg-do compile { target c++11 } }
25c7f1
+
25c7f1
+struct A
25c7f1
+{
25c7f1
+  void foo () &;
25c7f1
+};
25c7f1
+
25c7f1
+void
25c7f1
+bar (__UINTPTR_TYPE__ a)
25c7f1
+{
25c7f1
+  reinterpret_cast(a)->foo ();
25c7f1
+}