From patchwork Wed Apr 13 20:48:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 91109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7F81FB6F7C for ; Thu, 14 Apr 2011 06:48:43 +1000 (EST) Received: (qmail 9546 invoked by alias); 13 Apr 2011 20:48:42 -0000 Received: (qmail 9537 invoked by uid 22791); 13 Apr 2011 20:48:41 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Apr 2011 20:48:32 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3DKmWS6023919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Apr 2011 16:48:32 -0400 Received: from [127.0.0.1] ([10.3.113.3]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3DKmVOp030259 for ; Wed, 13 Apr 2011 16:48:32 -0400 Message-ID: <4DA60C1F.4000101@redhat.com> Date: Wed, 13 Apr 2011 16:48:31 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48594 (failure with overloaded ->* in template) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The code in build_offset_ref_from_tree was assuming that any ->* involved calling a bound pointer to member function. But that's not necessarily the case: it could be calling a pointer to function or functor by way of a pointer to data member or overloaded ->* operator. Tested x86_64-pc-linux-gnu, applying to trunk and 4.6. commit f97457d26c50790378457509461df06d5e8dbbdc Author: Jason Merrill Date: Wed Apr 13 14:45:47 2011 -0400 PR c++/48594 * decl2.c (build_offset_ref_call_from_tree): Fix calling a functor or pointer to (non-member) function. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 5b6f6ed..882bbf9 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/g++.dg/template/operator11.C b/gcc/testsuite/g++.dg/template/operator11.C new file mode 100644 index 0000000..8d6b77a --- /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)(); +}