From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7784 invoked by alias); 19 Jan 2016 18:54:23 -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 7715 invoked by uid 89); 19 Jan 2016 18:54:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=ranking, 588, sk:type_co X-HELO: mail-lf0-f65.google.com Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Jan 2016 18:54:16 +0000 Received: by mail-lf0-f65.google.com with SMTP id c134so14342230lfb.2 for ; Tue, 19 Jan 2016 10:54:16 -0800 (PST) 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=mqGoVVvLSqh9J/wEzDK5mqJuU4lJOu17jpcqs87CB8M=; b=O5zhIUUKrPvdVsA4pL4l/zmMYJHjBeAzAfKLgMY9sGvFPAjMp0TGEMtScvvBPmNMXR ioYgR8i7Oap4m0CwyQkDJnc6yFxXs3wuyNn/0vhDkdowwMQ0yNmgNxp8BGHmQ6Mrnhx8 vjDXAQN5k7dDaowA26dQ7+IW+/K3Sn9UYkNAB7VE4MKCF5RywH1qS/UvtMiV314QNyWr WptWB8bN2Yl/H4U1Eto5q53aPsX1stZWr+5UpEZZXFOgFiDHLyCbrpUN7maQwMFmwJ6R 2wCovYE33x6Kbe7yBlRq6DcjrGhbfCdUE6Req1HSm3/ia8FSJQL13s23o0fJ9horUup3 vmbA== X-Gm-Message-State: ALoCoQlf2Ir78Ovj5WJiWmavnX7KWsrVQvJAJXMlZ+GyUFVUYROH6o36MoSS06Gr83Qy9AJ0WckyH4CP7cqj8aAocVYVapVZ7w== X-Received: by 10.25.207.65 with SMTP id f62mr9408861lfg.73.1453229653402; Tue, 19 Jan 2016 10:54:13 -0800 (PST) Received: from arch.smware.local ([37.204.1.155]) by smtp.gmail.com with ESMTPSA id p66sm4247278lfe.42.2016.01.19.10.54.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jan 2016 10:54:12 -0800 (PST) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: palves@redhat.com, Artemiy Volkov Subject: [PATCH v2 09/11] [PR gdb/14441] gdb: gdbtypes: add rvalue references to overloading resolution Date: Tue, 19 Jan 2016 18:55:00 -0000 Message-Id: <1453229609-20159-10-git-send-email-artemiyv@acm.org> In-Reply-To: <1453229609-20159-1-git-send-email-artemiyv@acm.org> References: <1450661481-31178-1-git-send-email-artemiyv@acm.org> <1453229609-20159-1-git-send-email-artemiyv@acm.org> X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00460.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 3 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] ./ChangeLog: 2016-01-19 Artemiy Volkov * gdb/gdbtypes.c (rank_one_type): Implement overloading resolution rules regarding rvalue references. --- gdb/gdbtypes.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index fd17d3c..4bb98c9 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}; @@ -3464,6 +3466,20 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value) { struct rank rank = {0,0}; + /* Disallow an rvalue argument to bind to a non-const lvalue reference + parameter and an lvalue argument to bind to an rvalue reference + parameter. */ + + if ((value != NULL) + && + ((TYPE_CODE (parm) == TYPE_CODE_REF + && !TYPE_CONST (parm->main_type->target_type) + && VALUE_LVAL (value) == not_lval) + || + (TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF + && VALUE_LVAL (value) != not_lval))) + return INCOMPATIBLE_TYPE_BADNESS; + if (types_equal (parm, arg)) return EXACT_MATCH_BADNESS; @@ -3473,6 +3489,36 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value) if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) arg = check_typedef (arg); + /* 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_REFERENCE (parm) && TYPE_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_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.7.0