From patchwork Wed Jul 12 18:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 119323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1346625vqm; Wed, 12 Jul 2023 11:48:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZ4YUNcj2EoPeX3XZOdmPoPZ3LHkbj5RLNa3QdIDh4yx1bTo5HbfPQgaCXJsqvyRyg7kX1 X-Received: by 2002:a17:907:868a:b0:991:d414:d889 with SMTP id qa10-20020a170907868a00b00991d414d889mr4101229ejc.15.1689187715495; Wed, 12 Jul 2023 11:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689187715; cv=none; d=google.com; s=arc-20160816; b=LrZ8Md1wrKFA6URcyv8DFE9QZTGzXNgvXDUtvB0yGsUIH76WvGOnx8TwEOCm+Bp4Mb Bn0PdGXUfxwo55ebO5W6OqTgiBE8dIccL+x/CKQCEKbHtBKPM4j/x0ribL1wqE6N/QYh IHKlAXDH9QPuEdzR5i35Ca9AT98o3fmtFEn/iz7YXN4mAL/gkflX0UmMUfA1NeB1lmRH GoaB/CbtHiBUmW50MOIil4+7Dk9Ytnv2wVZVO6JHL3SxHYxqy9feIe3ov+W6SUiSci7i nqrWa2VD7gJEQx9sZG1Z8nthp2HsIsam8ed4+SKpiXSw04s/eFFNmcH1kJfliFMZURDJ Xp1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=dXfzgN+hK1yvncuPuqetq1V/PjIsy3E1FvVLkQg2Fc8=; fh=M5GO8duY/t9+1sJXvBSRQ4u8k9z8sLFDsSO1kARbltQ=; b=Dxw+ialJ88Wcn+9bhTO6E6TUdLoaJnhI6Hh/eIHaLrhyqOf3ebLlqMu3JWWDOCp6g4 SWyalWl05Z86jNlOFF9O4aFuOnkZFrei0yaS8fFhM8FOlEXL8gZOsNZPaTOIi+DL1iGL Aa40IF7YsMDGh/4lPaieEMw/RYqjjjTQG2tqosBUv6z6+IWkEXCUHQajEV0jVzHVcQHE E9JJ9XhYO+kTPCA6tV3IXSGfa27B8E0S5jH2myjLrkb0yTYJy6Tb1HWqqHZXz76jjgGA RaZ4BH7Auz1kkxXEG5a3Jwqw/7B6EhZK0kL2VbDageG7+FK0Nq6y4SAjCMW9BiVNvAvj o55A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=H6hJfhx9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b11-20020a170906490b00b0098897c46e08si4973409ejq.987.2023.07.12.11.48.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 11:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=H6hJfhx9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 407CE3857722 for ; Wed, 12 Jul 2023 18:48:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 407CE3857722 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689187713; bh=dXfzgN+hK1yvncuPuqetq1V/PjIsy3E1FvVLkQg2Fc8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=H6hJfhx9j58Yn79jcbrlSIgkFGAxBydk9mqhX+d68yU4WmIpiEXVthVeSHk9CmNYk VoXWM7N5BfQb5l3d6RsdRkcojjNZzL4Ajn39LxhCa7jYRXvgbQSWUS0ScNMsipf//e AH7vm1QXoDh2IeIbKsFGM6ZvYUY1YXKnXH8pVyNA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A3DFC3858D20 for ; Wed, 12 Jul 2023 18:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3DFC3858D20 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-BCkqU5xBMLuKEPR1WBI43A-1; Wed, 12 Jul 2023 14:47:50 -0400 X-MC-Unique: BCkqU5xBMLuKEPR1WBI43A-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7659c6caeaeso961132685a.3 for ; Wed, 12 Jul 2023 11:47:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689187669; x=1691779669; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dXfzgN+hK1yvncuPuqetq1V/PjIsy3E1FvVLkQg2Fc8=; b=kZC3MRAu1quA5Gx2alQXfG0ha9DYTG4+WoVSAyPGSt2ypaRo3TUVJVsN9/zyzkApJ2 aMGGOp39EdsMimBZgMwtvy6jUpHhHETEAcsWBEWkpczLcczxhO+dszq1fd7G3ahCKD2d ZL0Zc6i5i9C01yN9AtgFvxcX5HeT9hcIQ5uT7qXy/bDQNqfPtKZRw68BJflWTdXWyqQw 9cTGRMd95Z8sI5ncNU9HNTZWfpmHF6YcHA0+hPzzEp9HYv1xRu+5r5lew2xy+ryje2L5 JKlDT9qsDgupl1Y5Yggdqm1qFtxIsVw+pi0Z1J/eDo0AU2q47e0lcePgKS2wY2hxMlkr qFGg== X-Gm-Message-State: ABy/qLaEBovanTsbT2Fi8cfFxnZR59wocQuObcGVHXrb2ytOpx7OhBf8 Jxqb30oN1B7zse8KkaypkjHSydwOv1y9T8zILjrDa0H5cAjpJrl5NGQRx/oKpQA+F3xqzR0e9DC K7khN42EwglFqLhbeYdUpGechnYw6mWzjXuzqcIPPwFEbbL/zpDYZn+s8eVVzRHy7JDifCWp3bx g= X-Received: by 2002:a05:620a:24c2:b0:767:26d:1142 with SMTP id m2-20020a05620a24c200b00767026d1142mr23859001qkn.21.1689187669477; Wed, 12 Jul 2023 11:47:49 -0700 (PDT) X-Received: by 2002:a05:620a:24c2:b0:767:26d:1142 with SMTP id m2-20020a05620a24c200b00767026d1142mr23858984qkn.21.1689187669127; Wed, 12 Jul 2023 11:47:49 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id y9-20020a37e309000000b00767d47eb29bsm2326938qki.119.2023.07.12.11.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 11:47:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: non-standalone surrogate call template Date: Wed, 12 Jul 2023 14:47:47 -0400 Message-ID: <20230712184747.3213450-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.327.gaa9166bcc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771241697544630808 X-GMAIL-MSGID: 1771241697544630808 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. -- >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