From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25703 invoked by alias); 6 Jun 2016 19:23:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25521 invoked by uid 89); 6 Jun 2016 19:23:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:type_is, sk:TYPE_IS, ranking, selecting X-HELO: mail-lf0-f66.google.com Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 06 Jun 2016 19:22:58 +0000 Received: by mail-lf0-f66.google.com with SMTP id s186so7686555lfs.2 for ; Mon, 06 Jun 2016 12:22:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8RdLFypmNfxYJGzBAFbEe4tp66oc7v8dgrotdIwEf0Y=; b=P2MfkHARJC5G0U+YY7lXDbsacHOguaRxC9RkeW1X5fjHWd2EV+Z3a4Po7JIZdly7sE ie/YvF9gDG+Tve0xeJgTOnBexe04FdeE0ICJQ8LGInjlt+TFUxi+RO9qBKGKqGjc15p2 TslLVB8IUnVCfREpx3mC0g+LedHSsCoCKJABR3m1IafpyoLfbks7h/6oBo5/06w0hajb 9I94FTtZ+kZgpkq27GtHz/1FdwL8eXW2H8nQj1ciMa+cytsfOAt2RQ6L8xJuktvTTUyY UIJLdJqbsulLmvmg8ich1bDwqDUmTmISkyKVymw0WC5gt/SwUPHCsIHDLvUDM+I5cW/B hyvg== X-Gm-Message-State: ALyK8tLFLgF+AP9+32/CeZA3Nq6uSRRx6ntgapEyIXTbsgNjQKLUSW/gaUkSlkUEHfnQ+w== X-Received: by 10.25.146.81 with SMTP id u78mr1511911lfd.224.1465240975132; Mon, 06 Jun 2016 12:22:55 -0700 (PDT) Received: from localhost.localdomain (broadband-90-154-70-138.nationalcablenetworks.ru. [90.154.70.138]) by smtp.gmail.com with ESMTPSA id jv7sm1970253lbc.4.2016.06.06.12.22.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 12:22:54 -0700 (PDT) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: palves@redhat.com, keiths@redhat.com, Artemiy Volkov Subject: [PATCH v5 10/11] [PR gdb/14441] gdb: gdbtypes: add rvalue references to overloading resolution Date: Mon, 06 Jun 2016 19:23:00 -0000 Message-Id: <20160606192225.12384-11-artemiyv@acm.org> In-Reply-To: <20160606192225.12384-1-artemiyv@acm.org> References: <1458593958-25656-1-git-send-email-artemiyv@acm.org> <20160606192225.12384-1-artemiyv@acm.org> X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00112.txt.bz2 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] gdb/ChangeLog: 2016-06-06 Artemiy Volkov PR gdb/14441 * gdbtypes.c (rank_one_type): Implement overloading resolution rules regarding rvalue references. --- gdb/gdbtypes.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 3058504..392e619 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}; @@ -3500,15 +3502,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. */ -- 2.8.3