From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 7E8C63858D3C for ; Mon, 20 Sep 2021 18:42:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7E8C63858D3C Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-mT-9cg7SOrObEQPTRpTxfA-1; Mon, 20 Sep 2021 14:42:32 -0400 X-MC-Unique: mT-9cg7SOrObEQPTRpTxfA-1 Received: by mail-qv1-f72.google.com with SMTP id cf6-20020a05621403e600b0037a70d2f960so189057895qvb.13 for ; Mon, 20 Sep 2021 11:42:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=shDqxsxr6i8vMWrfovTwabpW6KV6PPCxxms6PW8Hktc=; b=e21fWjyaAbZeDolBLyVfZkrcSAhsFj865+eZzj+eNrTnJO339Lpy9CqvCTOqFccJey n2tBBciqIP6BiOJPxIfVrwylPvq9CT8PHIXn7le9ugoig0EcUDSNGxW1ZBdC/m0B7GCx J1z572XbqkQnjX/DEfKF+4+WeAAKPIj8N4ZUwhxOK4p198vy8MAmBIrIvJZSyztnC31H YugOHPJoq6MA0ud2mD6oxlcK4GjuGRv1urrOxsNCA4HErUuT1C9T1akLn4aSJq79yf2F IBv5G+ZKB8iOKKVIdkln51pqx+YjOKwWtQ3G5pANqdZMi1pV0UuOIJjH6dmlzMMdpx2F AunQ== X-Gm-Message-State: AOAM531Z5/+VmvzyOBsIyrpFRFs/qFzt6HhLJJH8/nE/NU7956c7MQwP gS12NzURyzLKj/xf67jRimV5/HzW8oruSfKki7714nVykjsQX9yryrXNVynwcnS1wa2qoMlEFkK hm2TIQSoWxUIX+7KIyw== X-Received: by 2002:a05:620a:2994:: with SMTP id r20mr25187895qkp.245.1632163348883; Mon, 20 Sep 2021 11:42:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPfw6bPUnYqqaPyerCI+lrSWUQyWEU2y1nTdIlr6bnAEFtvdf76qUgW2m4uI+oVY0WSkL3bA== X-Received: by 2002:a05:620a:2994:: with SMTP id r20mr25187862qkp.245.1632163348524; Mon, 20 Sep 2021 11:42:28 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id d9sm1989814qko.111.2021.09.20.11.42.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Sep 2021 11:42:27 -0700 (PDT) Message-ID: <19181760-52f1-babe-5b44-6471dea5b7bc@redhat.com> Date: Mon, 20 Sep 2021 14:42:26 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [PATCH] c++: consider built-in operator candidates first To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20210920164608.2740792-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20210920164608.2740792-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Sep 2021 18:42:34 -0000 On 9/20/21 12:46, Patrick Palka wrote: > During operator overload resolution, we currently consider non-member > candidates before built-in candidates. This didn't make a difference > before r12-3346, but after this change add_candidates will avoid > computing excess argument conversions if we've already seen a strictly > viable candidate, so it's better to consider built-in candidates first. Doesn't r12-3346 stop considering conversions after it sees a bad one, and later return to the bad candidate if there is no strictly viable candidate? How does this patch change that? Depending on the order of the candidates seems fragile. > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? > > gcc/cp/ChangeLog: > > * call.c (add_operator_candidates): Consider built-in operator > candidates before considering non-member candidates. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/conv17.C: Extend test. > --- > gcc/cp/call.c | 13 +++++++------ > gcc/testsuite/g++.dg/template/conv17.C | 7 +++++++ > 2 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/gcc/cp/call.c b/gcc/cp/call.c > index c5601d96ab8..c0da083758f 100644 > --- a/gcc/cp/call.c > +++ b/gcc/cp/call.c > @@ -6321,7 +6321,6 @@ add_operator_candidates (z_candidate **candidates, > vec *arglist, > int flags, tsubst_flags_t complain) > { > - z_candidate *start_candidates = *candidates; > bool ismodop = code2 != ERROR_MARK; > tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code); > > @@ -6333,6 +6332,12 @@ add_operator_candidates (z_candidate **candidates, > if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR) > flags &= ~LOOKUP_REWRITTEN; > > + /* Add built-in candidates to the candidate set. The standard says to > + rewrite built-in candidates, too, but there's no point. */ > + if (!rewritten) > + add_builtin_candidates (candidates, code, code2, fnname, arglist, > + flags, complain); > + > bool memonly = false; > switch (code) > { > @@ -6352,6 +6357,7 @@ add_operator_candidates (z_candidate **candidates, > > /* Add namespace-scope operators to the list of functions to > consider. */ > + z_candidate *start_candidates = *candidates; > if (!memonly) > { > tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE); > @@ -6423,11 +6429,6 @@ add_operator_candidates (z_candidate **candidates, > > if (!rewritten) > { > - /* The standard says to rewrite built-in candidates, too, > - but there's no point. */ > - add_builtin_candidates (candidates, code, code2, fnname, arglist, > - flags, complain); > - > /* Maybe add C++20 rewritten comparison candidates. */ > tree_code rewrite_code = ERROR_MARK; > if (cxx_dialect >= cxx20 > diff --git a/gcc/testsuite/g++.dg/template/conv17.C b/gcc/testsuite/g++.dg/template/conv17.C > index f0f10f2ef4f..87ecefb8de3 100644 > --- a/gcc/testsuite/g++.dg/template/conv17.C > +++ b/gcc/testsuite/g++.dg/template/conv17.C > @@ -61,3 +61,10 @@ concept E = requires { T().h(nullptr); }; > > static_assert(!E); > #endif > + > +// Verify that the strictly viable built-in operator+ candidate precludes > +// us from computing all argument conversions for the below non-strictly > +// viable non-member candidate. > +enum N { n }; > +int operator+(N&, B); > +int f = n + 42; >