diff mbox

C++ PATCH for c++/59818 (wrong overload with PMF)

Message ID 52E8280D.4090000@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 28, 2014, 9:58 p.m. UTC
In this testcase, we deduce "Bar const" for T and substitute it into the 
second parameter, accidentally getting a pointer to const member 
function because we forgot to strip the const from Bar.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 35f0fd76efae307b54f9fa11d39c988699eb4214
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jan 28 16:24:28 2014 -0500

    	PR c++/59818
    	* pt.c (tsubst_function_type): Make sure we keep the same function
    	quals.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6c68bae..011db2c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11189,6 +11189,8 @@  tsubst_function_type (tree t,
   else
     {
       tree r = TREE_TYPE (TREE_VALUE (arg_types));
+      /* Don't pick up extra function qualifiers from the basetype.  */
+      r = cp_build_qualified_type_real (r, type_memfn_quals (t), complain);
       if (! MAYBE_CLASS_TYPE_P (r))
 	{
 	  /* [temp.deduct]
diff --git a/gcc/testsuite/g++.dg/template/ptrmem24.C b/gcc/testsuite/g++.dg/template/ptrmem24.C
new file mode 100644
index 0000000..a419410
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ptrmem24.C
@@ -0,0 +1,20 @@ 
+// PR c++/59818
+
+template <class T>
+struct Identity {
+  typedef T type;
+};
+
+struct Foo {
+  template <typename T>
+  Foo(T*, void (Identity<T>::type::*m)(void));
+};
+
+struct Bar {
+  void Method(void) const;
+};
+
+void Bar::Method(void) const
+{
+  Foo foo(this, &Bar::Method);	// { dg-error "no match" }
+}