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: 1845578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HiX6yR4U; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4LpZ6fHVz1ypX for ; Tue, 10 Oct 2023 14:23:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 010EF3857029 for ; Tue, 10 Oct 2023 03:23:49 +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-Google-Smtp-Source: AGHT+IH5+2p2CzKEW8nWOjGmWcowVEjjbny1caOsODjjt7q09wcMpZUlI/CvEUNv7ULLvMYaRFYI1Q== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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" } +}