From patchwork Tue Oct 10 03:23:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 150461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2252344vqo; Mon, 9 Oct 2023 20:24:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEugZ+RPRgCOIftxol2hODE+V2ERW863a8qEDx2vWPhiu2S+cBZq5Do6O5yNEV/OXyHqeoh X-Received: by 2002:a17:906:9b:b0:9ba:3434:482c with SMTP id 27-20020a170906009b00b009ba3434482cmr1425183ejc.31.1696908256895; Mon, 09 Oct 2023 20:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696908256; cv=none; d=google.com; s=arc-20160816; b=IuAihn8m7DnSiMBTCMDcxWCsBHIZDDQ8/6R2Zfj57tW/up0FAn4Y9YbGyj686xJNM9 P+Hj3vPazry2miFsFstVAP6Xk8jtFciqvtF8nNLwxEgYbUVVTDSHBF7Cl65IFvdHUkiL A98sVRKw8lJDe4NtcjyXZsH2cHP/03ykM+pH1Z+sB8HOnF5ayJ7L08mzCDLMxV5624Ec 3LNFk0Eg0LUO8AEBO0ISRvXMfGL2blVORSqmVMm/3BMYb+aJXheJenRO0dOkzJS0f4mp Fc/HRgQr61i0kRnhOvsp6G2eXmhFzh7SVOqevCCJ2S+gntY70aDYHcK214eE7+OLcfQO j2ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=LvDWfMUX1SQ6gzARClvcTr+hhD3gbrtXoi4k7XHjby0=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=JHVl+l7zKV3FFZH4GVGu+IfygSSDRj+tQMuwa/fd69iDcOU20/cL/nnmfEgi4biNPW 0FB8jaly3zRAsY1GTgX62Lr07jNijMsd9BvRdrQsEswDCS66ndm392E2TSQs4DuIolY6 NQMkksUegO5cK3J9ujo/yhzVfmpNq4Rm+gbeD1T6+DbCOZVw/Kf16fgxykeIBRAwPX3s jeLGucuImfe+WyjE2OuFb5m4AK8kkvCGj9FQhX98u9G3fJ10wcg89U0ROCBeJIpDhnV/ L5ng5frpaMRyWkEZgsfbPPIZoMhDs1Wt85beAj8kcTRz6xg5xhgI1mEXkV5CfmLZ+A/U oyyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HiX6yR4U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n2-20020a1709061d0200b009a1f53509a7si5148020ejh.135.2023.10.09.20.24.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 20:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HiX6yR4U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 179F7385772B for ; Tue, 10 Oct 2023 03:24:02 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0EA6B385840F for ; Tue, 10 Oct 2023 03:23:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EA6B385840F 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=1696908191; 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: in-reply-to:in-reply-to:references:references; bh=LvDWfMUX1SQ6gzARClvcTr+hhD3gbrtXoi4k7XHjby0=; b=HiX6yR4Ufd3pomqKHZ9uHHzlnCXg/iAQoT5F42FT8L/H0B4Tq4iQpMVzSDTT55QaRwn/f8 MHdFwwEh0YuCLkvn2kBdK5Cxo2kZSkdNF/4AZL66qmWzqxrlaMva6gPPNl8ZFThZSNlUpF sOLnlUMTOZYSPS8fHy8UtsPynnv36GU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-J5d4PNWbOHCkQogKttRhfg-1; Mon, 09 Oct 2023 23:23:05 -0400 X-MC-Unique: J5d4PNWbOHCkQogKttRhfg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-66cf8d4b5e4so6856d6.3 for ; Mon, 09 Oct 2023 20:23:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696908184; x=1697512984; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LvDWfMUX1SQ6gzARClvcTr+hhD3gbrtXoi4k7XHjby0=; b=KtVljYy7F6DepXPbYk4G93/tarzOcM5bsUJowhMS+E6dVE+7Bt5ZkKjrHJA+0zSM9v 3kZ6GL9yLolhOix2cRmzMrycVwoKSCljy4ywOkVXuQBCxgik45ZFzMdndZGLxxLTQVjd 2xK2kjsyUolPDAolswr0m7BqCCZfN46U71BxvGCbtQg0EEVB/xPao7GItCAXypkUmLAs eTcbHC//yeBjJilKoEdOFpw0gyFz1EaX9gF5kMKkC6dXDmEumZMnSs5TrVUScBhfkrFN 9oqDqiF/iuvKlKBXiP4vFRn9GkDOy16iTVNKIcf0VYOPuZJ5okBtdA5aet3lL6vLsbw6 VHtA== X-Gm-Message-State: AOJu0YzPYuoBAY7hG8tKx7neym/Lx5dxI+ys8fW1Svz+0K6Gh5C7JgpJ 9tMV0eLKYc0bGvL0NihDqk2Rw2RJzj8T8pvwG2FotyxuYNh9bC+OtQzeH8KP9byPcYENACNlQ0Z Y5SnVETnO/98PbGqIMhpxO8a36Lgh4cGcBdoRg7eAV71nT1ExejaG0S+IoMz9wS8jNg2X/jem7K s= X-Received: by 2002:ad4:5949:0:b0:64f:51fe:859c with SMTP id eo9-20020ad45949000000b0064f51fe859cmr21226393qvb.43.1696908184506; Mon, 09 Oct 2023 20:23:04 -0700 (PDT) X-Received: by 2002:ad4:5949:0:b0:64f:51fe:859c with SMTP id eo9-20020ad45949000000b0064f51fe859cmr21226382qvb.43.1696908184192; Mon, 09 Oct 2023 20:23:04 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c10-20020a0cf2ca000000b0065afd35c762sm4346144qvm.91.2023.10.09.20.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 20:23:03 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/2] c++: note other candidates when diagnosing deletedness Date: Mon, 9 Oct 2023 23:23:00 -0400 Message-ID: <20231010032300.1057862-2-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.325.g3a06386e31 In-Reply-To: <20231010032300.1057862-1-ppalka@redhat.com> References: <20231010032300.1057862-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779337272661172317 X-GMAIL-MSGID: 1779337272661172317 With the previous improvements in place, we can easily extend our deletedness diagnostic to note the other candidates: deleted16.C: In function ‘int main()’: deleted16.C:10:4: error: use of deleted function ‘void f(int)’ 10 | f(0); | ~^~~ deleted16.C:5:6: note: declared here 5 | void f(int) = delete; | ^ deleted16.C:5:6: note: candidate: ‘void f(int)’ (deleted) deleted16.C:6:6: note: candidate: ‘void f(...)’ 6 | void f(...); | ^ deleted16.C:7:6: note: candidate: ‘void f(int, int)’ 7 | void f(int, int); | ^ deleted16.C:7:6: note: candidate expects 2 arguments, 1 provided These notes are disabled when a deleted special member function is selected primarily because it introduces a lot of new "cannot bind reference" errors in the testsuite when noting non-viable candidates, e.g. in cpp0x/initlist-opt1.C we would need to expect an error at A(A&&). gcc/cp/ChangeLog: * call.cc (build_over_call): Call print_z_candidates when diagnosing deletedness. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/deleted16.C: New test. --- gcc/cp/call.cc | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/deleted16.C | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/deleted16.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 648d383ca4e..55fd71636b1 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -9873,7 +9873,15 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (DECL_DELETED_FN (fn)) { if (complain & tf_error) - mark_used (fn); + { + mark_used (fn); + /* Note the other candidates we considered unless we selected a + special member function since the mismatch reasons for other + candidates are usually uninteresting, e.g. rvalue vs lvalue + reference binding . */ + if (cand->next && !special_memfn_p (fn)) + print_z_candidates (input_location, cand, /*only_viable_p=*/false); + } return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted16.C b/gcc/testsuite/g++.dg/cpp0x/deleted16.C new file mode 100644 index 00000000000..9fd2fbb1465 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/deleted16.C @@ -0,0 +1,11 @@ +// Verify we note other candidates when a deleted function is +// selected by overload resolution. +// { dg-do compile { target c++11 } } + +void f(int) = delete; // { dg-message "declared here|candidate" } +void f(...); // { dg-message "candidate" } +void f(int, int); // { dg-message "candidate" } + +int main() { + f(0); // { dg-error "deleted" } +}