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.129.124]) by sourceware.org (Postfix) with ESMTPS id A20C53858D33 for ; Mon, 17 Jul 2023 17:44:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A20C53858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689615850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cHmnqBA3XsSBN4ZbXV/viWJOsWx23AkQ0yZvmJw5pqk=; b=HKNKLAIn4YtAitrg35HnJNGn3zP4CBigINoiVR87+fZzYbpkHIzrPWvkuV1S0lUDB42NKG 6xbx1vMXPmFuWrEGCpLTXHzu85fCz7REAEjpPzb9b1hKJfpUXlj+bAqjmOqenzTMd6U87C uZbEMl5WpVZCI4DYf1tEJeS4YOTAoc0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-_6WQUMCIMSySIN_Gn7tkhA-1; Mon, 17 Jul 2023 13:44:07 -0400 X-MC-Unique: _6WQUMCIMSySIN_Gn7tkhA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-765986c0568so718410885a.1 for ; Mon, 17 Jul 2023 10:44:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689615846; x=1692207846; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cHmnqBA3XsSBN4ZbXV/viWJOsWx23AkQ0yZvmJw5pqk=; b=epXqgXNcyWoha8g8X+uvOcmvylWfaKVv99YaYu3uC3uEMxWqH9Zkaudkff0oq1KJbT K2/FiFHzHcUfp9Ye0J90XZZyItU1huhZgphH02jjGU2bKJUEeiXmbzuVERyu7ot3YrkK /gcHNDiSLz4e7Y7OU5Pc7UOTLfEGGd2hAFkE4auNgHpOsIzGqaN2P0Q81jNPI8QfAQoP 3zzhBd0NpsJh16jVxHZvwLwx8uKpMmJr2yumDgB/EGyrlCeJYbRtw04T+/XNZGrXPfrd BZkkeo8KRTQ6SeF+mnDmtTF02dO+p46doI3d47A9Eww+Qq3SP5eN7iPhgDaa2J6sU69X j0Kw== X-Gm-Message-State: ABy/qLbeMH+Mos9qxwoebPZKEDPASgbS5+4C8dMNT+JUwtFUCmCfNTvM clBVEIIkLRF8ssgE4ceAxJKwhXynLf/KsdDCx1h8hEpAFD5fq0fCDAHVbT8YAGPWcgtvN1p1A3J Tg7h0paBm1pW+bBIfCg== X-Received: by 2002:a05:620a:29c3:b0:767:5bdf:3e22 with SMTP id s3-20020a05620a29c300b007675bdf3e22mr19863036qkp.40.1689615846597; Mon, 17 Jul 2023 10:44:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWz+uI3f16Kkq/id7ib+iI4+zN9LX7CYQLC6GIyNsSeDGysC6WHoxHG6cX8oTvPuCn22Te/A== X-Received: by 2002:a05:620a:29c3:b0:767:5bdf:3e22 with SMTP id s3-20020a05620a29c300b007675bdf3e22mr19863021qkp.40.1689615846329; Mon, 17 Jul 2023 10:44:06 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id p19-20020a05620a113300b0075b168fcde9sm6231943qkk.77.2023.07.17.10.44.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jul 2023 10:44:05 -0700 (PDT) Message-ID: <1e51179b-c1af-b76e-409d-c55da2976fae@redhat.com> Date: Mon, 17 Jul 2023 13:44:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] c++: non-standalone surrogate call template To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230712184747.3213450-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230712184747.3213450-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=-12.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_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 7/12/23 14:47, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? There might be an existing PR for this issue but Bugzilla search > seems to be timing out for me currently. OK. > -- >8 -- > > I noticed we were accidentally preventing ourselves from considering > a pointer/reference-to-function conversion function template if it's > not the first conversion function that's considered, which for the > testcase below resulted in us accepting the B call but not the A call > despite the only difference between A and B being the order of member > declarations. This patch fixes this so that the outcome of overload > resolution doesn't arbitrarily depend on declaration order in this > situation. > > gcc/cp/ChangeLog: > > * call.cc (add_template_conv_candidate): Don't check for > non-empty 'candidates' here. > (build_op_call): Check it here, before we've considered any > conversion functions. > > gcc/testsuite/ChangeLog: > > * g++.dg/overload/conv-op5.C: New test. > --- > gcc/cp/call.cc | 24 ++++++++++++++---------- > gcc/testsuite/g++.dg/overload/conv-op5.C | 18 ++++++++++++++++++ > 2 files changed, 32 insertions(+), 10 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/overload/conv-op5.C > > diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc > index 81935b83908..119063979fa 100644 > --- a/gcc/cp/call.cc > +++ b/gcc/cp/call.cc > @@ -3709,12 +3709,6 @@ add_template_conv_candidate (struct z_candidate **candidates, tree tmpl, > tree return_type, tree access_path, > tree conversion_path, tsubst_flags_t complain) > { > - /* Making this work broke PR 71117 and 85118, so until the committee resolves > - core issue 2189, let's disable this candidate if there are any call > - operators. */ > - if (*candidates) > - return NULL; > - > return > add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE, > NULL_TREE, arglist, return_type, access_path, > @@ -5290,6 +5284,8 @@ build_op_call (tree obj, vec **args, tsubst_flags_t complain) > LOOKUP_NORMAL, &candidates, complain); > } > > + bool any_call_ops = candidates != nullptr; > + > convs = lookup_conversions (type); > > for (; convs; convs = TREE_CHAIN (convs)) > @@ -5306,10 +5302,18 @@ build_op_call (tree obj, vec **args, tsubst_flags_t complain) > continue; > > if (TREE_CODE (fn) == TEMPLATE_DECL) > - add_template_conv_candidate > - (&candidates, fn, obj, *args, totype, > - /*access_path=*/NULL_TREE, > - /*conversion_path=*/NULL_TREE, complain); > + { > + /* Making this work broke PR 71117 and 85118, so until the > + committee resolves core issue 2189, let's disable this > + candidate if there are any call operators. */ > + if (any_call_ops) > + continue; > + > + add_template_conv_candidate > + (&candidates, fn, obj, *args, totype, > + /*access_path=*/NULL_TREE, > + /*conversion_path=*/NULL_TREE, complain); > + } > else > add_conv_candidate (&candidates, fn, obj, > *args, /*conversion_path=*/NULL_TREE, > diff --git a/gcc/testsuite/g++.dg/overload/conv-op5.C b/gcc/testsuite/g++.dg/overload/conv-op5.C > new file mode 100644 > index 00000000000..b7724908b62 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/overload/conv-op5.C > @@ -0,0 +1,18 @@ > +// { dg-do compile { target c++11 } } > + > +template using F = int(*)(T); > +using G = int(*)(int*); > + > +struct A { > + template operator F(); // #1 > + operator G() = delete; // #2 > +}; > + > +int i = A{}(0); // selects #1 > + > +struct B { > + operator G() = delete; // #2 > + template operator F(); // #1 > +}; > + > +int j = B{}(0); // selects #1