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 ESMTPS id A3DFC3858D20 for ; Wed, 12 Jul 2023 18:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3DFC3858D20 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=1689187671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dXfzgN+hK1yvncuPuqetq1V/PjIsy3E1FvVLkQg2Fc8=; b=Dzl6ArB9s7h1mTCc8aH7aRWBoAsn72ZYIiu2cbXpmQbK/jfzTvrb0kEFUy3kDHtRKqYTp6 +aIVsn59oLB1egIdIX1iAEKWdzLBkGxFO5q/8sXz2b3aOcgBtYSGUspwr98gBD5bjIgk8F QSw7qxuas63PW+knO2DeFE6NUu0ETWc= 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) From: Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 -- 2.41.0.327.gaa9166bcc0