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: 1806947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BVVGjlIP; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1RZh5NbSz20cD for ; Thu, 13 Jul 2023 04:48:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BEDD3858D20 for ; Wed, 12 Jul 2023 18:48:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BEDD3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689187690; 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=BVVGjlIP4v2RdbGb3kXkjIjfEcKScFAvGxV8+nXIjsafBF8k4H/7qzAzRJRI3xH0W nEU6n5OGJHzSQxwNcZjA9mG9KFT15wQYBnGH3grVc2c0Za5M7SQL7IeRd2Y+m0KkXZ 4Q9TDPGnaWFY88Zx9RdyJqhATadQzQdGWqbIQN+o= 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-Google-Smtp-Source: APBJJlGMwo4NjoW9HlLmxM1ZW0vFsSZZTAdSSr8A1kHEtvRnN/61MJTOyHywIJxFLT/Nd1OtMYq3JQ== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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