From 516d9427ed538547a182833b2cf16f557c932710 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 13 Apr 2011 16:50:26 -0400 Subject: [PATCH] re PR c++/48594 (Rejects valid with pointer-to-member in template) PR c++/48594 * decl2.c (build_offset_ref_call_from_tree): Fix calling a functor or pointer to (non-member) function. From-SVN: r172394 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 16 +++++++++----- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/operator11.C | 25 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/operator11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a0d7cc249b3..05f12bed4eb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-04-13 Jason Merrill + + PR c++/48594 + * decl2.c (build_offset_ref_call_from_tree): Fix calling a functor + or pointer to (non-member) function. + 2011-04-13 Jakub Jelinek PR c++/48570 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 5b6f6edf3af..882bbf9f88e 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -4081,10 +4081,13 @@ build_offset_ref_call_from_tree (tree fn, VEC(tree,gc) **args) parameter. That must be done before the FN is transformed 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_addr_expr (object, tf_warning_or_error); - VEC_safe_insert (tree, gc, *args, 0, object); + if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE) + { + object = build_non_dependent_expr (object); + if (TREE_CODE (fn) == DOTSTAR_EXPR) + object = cp_build_addr_expr (object, 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); } @@ -4103,7 +4106,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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4e33fb2ba8..433faa66b19 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-04-13 Jason Merrill + + * g++.dg/template/operator11.C: New. + 2011-04-13 Jakub Jelinek PR middle-end/48591 diff --git a/gcc/testsuite/g++.dg/template/operator11.C b/gcc/testsuite/g++.dg/template/operator11.C new file mode 100644 index 00000000000..8d6b77ab454 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/operator11.C @@ -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 +void f() +{ + (a->*1)(); + (b->*1)(); + (cp->*cpfn)(); + (cp->*cfunc)(); +} -- 2.30.2