From patchwork Fri Mar 10 20:04:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 19522 Received: (qmail 71303 invoked by alias); 10 Mar 2017 20:14:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 68494 invoked by uid 89); 10 Mar 2017 20:14:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Mar 2017 20:14:24 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6D4F4DB14 for ; Fri, 10 Mar 2017 20:04:50 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AK4lX5029240 for ; Fri, 10 Mar 2017 15:04:50 -0500 From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH v6 10/11] Add rvalue references to overloading resolution Date: Fri, 10 Mar 2017 12:04:45 -0800 Message-Id: <1489176286-27973-11-git-send-email-keiths@redhat.com> In-Reply-To: <1489176286-27973-1-git-send-email-keiths@redhat.com> References: <1489176286-27973-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes This patch introduces changes to rank_one_type() dealing with ranking an rvalue reference type when selecting a best viable function from a set of candidate functions. The 4 new added rules for rvalue references are: 1) An rvalue argument cannot be bound to a non-const lvalue reference parameter and an lvalue argument cannot be bound to an rvalue reference parameter. [C++11 13.3.3.1.4p3] 2) If a conversion to one type of reference is an identity conversion, and a conversion to the second type of reference is a non-identity conversion, choose the first type. [C++11 13.3.3.2p3] 3) An rvalue should be first tried to bind to an rvalue reference, and then to an lvalue reference. [C++11 13.3.3.2p3] 4) An lvalue reference to a function gets higher priority than an rvalue reference to a function. [C++11 13.3.3.2p3] There are no changes to this patch from v5. NOTE: This patch is not exactly correct. See c++/15372 for tracking overload resolution bugs. gdb/ChangeLog PR gdb/14441 From Artemiy Volkov * gdbtypes.c (rank_one_type): Implement overloading resolution rules regarding rvalue references. --- gdb/ChangeLog | 7 +++++++ gdb/gdbtypes.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ee3de5c..338f412 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -2,6 +2,13 @@ PR gdb/14441 From Artemiy Volkov + * gdbtypes.c (rank_one_type): Implement overloading + resolution rules regarding rvalue references. + +2017-MM-DD Keith Seitz + + PR gdb/14441 + From Artemiy Volkov * aarch64-tdep.c (aarch64_type_align) (aarch64_extract_return_value, aarch64_store_return_value): Change lvalue reference type checks to general reference type checks. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index defc00d..6f3aeab 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -58,6 +58,8 @@ const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0}; const struct rank BOOL_CONVERSION_BADNESS = {3,0}; const struct rank BASE_CONVERSION_BADNESS = {2,0}; const struct rank REFERENCE_CONVERSION_BADNESS = {2,0}; +const struct rank LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS = {5,0}; +const struct rank DIFFERENT_REFERENCE_TYPE_BADNESS = {6,0}; const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0}; const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0}; const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0}; @@ -3611,15 +3613,65 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value) { struct rank rank = {0,0}; - if (types_equal (parm, arg)) - return EXACT_MATCH_BADNESS; - /* Resolve typedefs */ if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) parm = check_typedef (parm); if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) arg = check_typedef (arg); + if (value != NULL) + { + /* An rvalue argument cannot be bound to a non-const lvalue + reference parameter... */ + if (VALUE_LVAL (value) == not_lval + && TYPE_CODE (parm) == TYPE_CODE_REF + && !TYPE_CONST (parm->main_type->target_type)) + return INCOMPATIBLE_TYPE_BADNESS; + + /* ... and an lvalue argument cannot be bound to an rvalue + reference parameter. [C++ 13.3.3.1.4p3] */ + if (VALUE_LVAL (value) != not_lval + && TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF) + return INCOMPATIBLE_TYPE_BADNESS; + } + + if (types_equal (parm, arg)) + return EXACT_MATCH_BADNESS; + + /* An lvalue reference to a function should get higher priority than an + rvalue reference to a function. */ + + if (value != NULL && TYPE_CODE (arg) == TYPE_CODE_RVALUE_REF + && TYPE_CODE (TYPE_TARGET_TYPE (arg)) == TYPE_CODE_FUNC) + { + return (sum_ranks (rank_one_type (parm, + lookup_pointer_type (TYPE_TARGET_TYPE (arg)), NULL), + DIFFERENT_REFERENCE_TYPE_BADNESS)); + } + + /* If a conversion to one type of reference is an identity conversion, and a + conversion to the second type of reference is a non-identity conversion, + choose the first type. */ + + if (value != NULL && TYPE_IS_REFERENCE (parm) && TYPE_IS_REFERENCE (arg) + && TYPE_CODE (parm) != TYPE_CODE (arg)) + { + return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), + TYPE_TARGET_TYPE (arg), NULL), DIFFERENT_REFERENCE_TYPE_BADNESS)); + } + + /* An rvalue should be first tried to bind to an rvalue reference, and then to + an lvalue reference. */ + + if (value != NULL && TYPE_CODE (parm) == TYPE_CODE_REF + && VALUE_LVAL (value) == not_lval) + { + if (TYPE_IS_REFERENCE (arg)) + arg = TYPE_TARGET_TYPE (arg); + return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL), + LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS)); + } + /* See through references, since we can almost make non-references references. */