From patchwork Tue May 3 20:09:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 93889 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 73DB4B6F65 for ; Wed, 4 May 2011 06:09:55 +1000 (EST) Received: (qmail 26500 invoked by alias); 3 May 2011 20:09:53 -0000 Received: (qmail 26486 invoked by uid 22791); 3 May 2011 20:09:51 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_FN, 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; Tue, 03 May 2011 20:09:30 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p43K9Uk7029576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 May 2011 16:09:30 -0400 Received: from localhost (ovpn-113-28.phx2.redhat.com [10.3.113.28]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p43K9Sou026447 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 3 May 2011 16:09:29 -0400 Received: by localhost (Postfix, from userid 500) id 7C30C2A0298; Tue, 3 May 2011 22:09:27 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Jason Merrill Subject: [PATCH] Fix PR c++/48838 X-URL: http://www.redhat.com Date: Tue, 03 May 2011 22:09:26 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 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 Hello, This is another fallout of the fix for PR c++/47172, where we started to make finish_call_expr make member function call expressions that have a dependent "this" pointer be recognized by type_dependent_expression_p as being type dependent. The problem is that a node being a BASELINK is not enough to mean that it represents a non-static member function, as it can also represent a static member function. In this patch I try to look at the actual function wrapped by the BASELINK to make sure it's a non-static member. Tested and bootstrapped on x86_64-unknown-linux-gnu against trunk. Another bootstrap is on it way on the 4.6 branch. OK to commit to trunk and 4.6 if it passes? gcc/cp PR c++/48838 * cp-tree.h (non_static_member_function_p): Declare new function. * tree.c (non_static_member_function_p): Define it. * semantics.c (finish_call_expr): Use it. gcc/testsuite PR c++/48838 * g++.dg/template/member9.C: New test case. --- gcc/cp/cp-tree.h | 1 + gcc/cp/semantics.c | 3 +-- gcc/cp/tree.c | 28 ++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/template/member9.C | 21 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/member9.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 961581e..d694e25 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5430,6 +5430,7 @@ extern tree get_fns (tree); extern tree get_first_fn (tree); extern tree ovl_cons (tree, tree); extern tree build_overload (tree, tree); +extern bool non_static_member_function_p (tree); extern const char *cxx_printable_name (tree, int); extern const char *cxx_printable_name_translate (tree, int); extern tree build_exception_variant (tree, tree); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 815824a..baa8fd4 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2039,8 +2039,7 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual, is not included in *ARGS even though it is considered to be part of the list of arguments. Note that this is related to CWG issues 515 and 1005. */ - || (((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE) - || BASELINK_P (fn)) + || (non_static_member_function_p (fn) && current_class_ref && type_dependent_expression_p (current_class_ref))) { diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 0f2f86c..039f795 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1482,6 +1482,34 @@ build_overload (tree decl, tree chain) return ovl_cons (decl, chain); } +/* Return TRUE if FN is a non-static member function, FALSE otherwise. + This function looks into BASELINK and OVERLOAD nodes. */ + +bool +non_static_member_function_p (tree fn) +{ + if (fn == NULL_TREE) + return false; + + if (BASELINK_P (fn)) + { + tree type = TREE_TYPE (fn); + + if (type && TREE_CODE (type) == METHOD_TYPE) + return true; + else if (type && TREE_CODE (type) == FUNCTION_TYPE) + return false; + /* This is an overload. Lets look into its current value. */ + fn = get_fns (BASELINK_FUNCTIONS (fn)); + } + + if (TREE_CODE (fn) == OVERLOAD) + fn = OVL_CURRENT (fn); + + return (DECL_P (fn) + && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)); +} + #define PRINT_RING_SIZE 4 diff --git a/gcc/testsuite/g++.dg/template/member9.C b/gcc/testsuite/g++.dg/template/member9.C new file mode 100644 index 0000000..f15272d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/member9.C @@ -0,0 +1,21 @@ +// Origin PR c++/48838 +// { dg-do compile } + +class DUChainItemSystem +{ +public: + + template + void registerTypeClass(); + + static DUChainItemSystem& self(); +}; + +template +struct DUChainItemRegistrator +{ + DUChainItemRegistrator() + { + DUChainItemSystem::self().registerTypeClass(); + } +};