]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/48594 (Rejects valid with pointer-to-member in template)
authorJason Merrill <jason@redhat.com>
Thu, 21 Apr 2011 02:56:39 +0000 (22:56 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 Apr 2011 02:56:39 +0000 (22:56 -0400)
PR c++/48594
* decl2.c (build_offset_ref_call_from_tree): Fix calling a functor
or pointer to (non-member) function.

From-SVN: r172803

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/operator11.C [new file with mode: 0644]

index 2441d6522b2fe8b375676426b97b52a2bbfdeb84..00542f91bf881002a314a86af9e91ef79d4e1e82 100644 (file)
@@ -1,3 +1,9 @@
+2011-04-20  Jason Merrill  <jason@redhat.com>
+
+       PR c++/48594
+       * decl2.c (build_offset_ref_call_from_tree): Fix calling a functor
+       or pointer to (non-member) function.
+
 2011-04-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/46304
index 90adc68c4932cb71871503140ba2bd239a8a140e..d27ed433d4da5fd02a9c3c3f0ee12d6f2d4254f0 100644 (file)
@@ -3911,9 +3911,12 @@ build_offset_ref_call_from_tree (tree fn, VEC(tree,gc) **args)
         because we depend on the form of FN.  */
       make_args_non_dependent (*args);
       object = build_non_dependent_expr (object);
-      if (TREE_CODE (fn) == DOTSTAR_EXPR)
-       object = cp_build_unary_op (ADDR_EXPR, object, 0, tf_warning_or_error);
-      VEC_safe_insert (tree, gc, *args, 0, object);
+      if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
+       {
+         if (TREE_CODE (fn) == DOTSTAR_EXPR)
+           object = cp_build_unary_op (ADDR_EXPR, object, 0, tf_warning_or_error);
+         VEC_safe_insert (tree, gc, *args, 0, object);
+       }
       /* Now that the arguments are done, transform FN.  */
       fn = build_non_dependent_expr (fn);
     }
@@ -3933,7 +3936,10 @@ build_offset_ref_call_from_tree (tree fn, VEC(tree,gc) **args)
       VEC_safe_insert (tree, gc, *args, 0, object_addr);
     }
 
-  expr = cp_build_function_call_vec (fn, args, tf_warning_or_error);
+  if (CLASS_TYPE_P (TREE_TYPE (fn)))
+    expr = build_op_call (fn, args, tf_warning_or_error);
+  else
+    expr = cp_build_function_call_vec (fn, args, tf_warning_or_error);
   if (processing_template_decl && expr != error_mark_node)
     expr = build_min_non_dep_call_vec (expr, orig_fn, orig_args);
 
index 253c8321769a32e8e8e725f55f7de268471b39f3..133776ef7305e5b83991a833b53533f6a9868d0f 100644 (file)
@@ -1,3 +1,7 @@
+2011-04-20  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/template/operator11.C: New.
+
 2011-04-19  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/ext/complex7.C: New.
diff --git a/gcc/testsuite/g++.dg/template/operator11.C b/gcc/testsuite/g++.dg/template/operator11.C
new file mode 100644 (file)
index 0000000..8d6b77a
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/48594
+// Test for uses of (X->*Y)() that don't actually involve a
+// pointer to member function.
+
+struct A { } a;
+struct B { } b;
+struct C * cp;
+
+struct Func { void operator()(); };
+Func operator->* (A, int);
+
+typedef void (*pfn)();
+pfn operator->* (B, int);
+
+pfn C::*cpfn;
+Func C::*cfunc;
+
+template <class T>
+void f()
+{
+  (a->*1)();
+  (b->*1)();
+  (cp->*cpfn)();
+  (cp->*cfunc)();
+}