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.129.124]) by sourceware.org (Postfix) with ESMTPS id E29EB3858C2A for ; Mon, 23 Oct 2023 23:52:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E29EB3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E29EB3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698105124; cv=none; b=FvT+2X6J5Cle0igLCSwFh7jnClP9J7PD86W5hUIpCrLQjpVfPihI/uI5f0BDZD92qt/VWM4Pa6+uPSYtqiENuh3cYIvpF/sNXDgQt5+M+Z5/Ioev9z597OWt1Hdx+l7bMKye6q53X5RZldbQ54tl6i+pglnFqKH022Nm2kVG7Fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698105124; c=relaxed/simple; bh=341VtsUASDPxgkQNw2VHyQUybqGMgeztW5xbcYYa1wo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Vp1s4r7iT2kD3UokLSGDfEo94TGJSmGQNh+PNXK2viCyHiIiSJ54cncF0zpCh7sQd4xK9OadL1P1/YYKttBJ8Zlbvu1OfkIuPWYj1pgBDT8QE4oR+oLDJFAj+nCYHtvgmDuM3i/KHzqd3zTLC14+uauRnC+7FWQKg4m9trlVe04= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698105122; 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=T97WVqOBWGXuSRNMpCL9tctTaykTAX0IwGc6FHyCu34=; b=UE727gQJU3NaoozUFGcjrkkjJqCc/uA5vqYHwIla3sUvoVtp+VzztHf/mzQw5QxYWje/nv O2Shy6WZOOdiJH04MfCU82Mtixf2Cwck8LC4v1/8XMwODGVEw0jcFoIyRe30C7ddpTigpT mfpCJHlf3YLOYVWI6/9/vJcTANSf5Oo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-183--O5GIhkfPxSTvXFde-1qdg-1; Mon, 23 Oct 2023 19:52:01 -0400 X-MC-Unique: -O5GIhkfPxSTvXFde-1qdg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-41e172143c3so40061161cf.1 for ; Mon, 23 Oct 2023 16:52:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698105120; x=1698709920; 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=T97WVqOBWGXuSRNMpCL9tctTaykTAX0IwGc6FHyCu34=; b=iGo1FY7D1AmWuH2SxVXyxHpXOeiT3RCuUqS2PHzfc1ZkkIA+maOP4A0ZWMK7JhPp9l hHKjJUFo6BKFDyheZ85lDQapHL6I1AV6O3/3VBIu6yiPnnVPWrP8e3wBKPzY+F/BhtqA 2eRIYsc3J3/YjofhUbvgQJyrC1aIkbv5m51wxkGvhtQN4MSHDAgH2CM2Dm2GpN+bqCXj G17G/lFxmJ+5tZzrbk4n+LN1LOPFVc5GVJ5TOANjX2JuhzDuWhycnnOi+2osl+kE89IS XXoEQps+4Zi/XftHHBKpwA54PjYa+sFWcPnB0Z/uCCtZ6GziWB1uOa0QxEC0k7o+3ArY j+qA== X-Gm-Message-State: AOJu0Ywxx6XmMAouPXJmanuTxL5GlYueB9/IUy8HjuPIDoFR5D7wX4xX oAOluz6jMGCAxe/h/77t9y/qH2K9zX3nDHO7vE9aLtixr0TjICF/Nm7PhYqm53m+5jdntV2VAiL tOInil8f1G+/RunDRapt5O6JJdHmIVipjwZQMI/blyshAVgPFXgIA3v2BXUVzRUl8DaHNvORyC/ g= X-Received: by 2002:a05:622a:1a05:b0:417:953c:ff57 with SMTP id f5-20020a05622a1a0500b00417953cff57mr15066495qtb.14.1698105120405; Mon, 23 Oct 2023 16:52:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHecYuKrTXqWe/zbn1ZFmvq60nWpCNch1V8FHMu0FznoPnDdPESPuF9TfXV9/oiFKICom+0fQ== X-Received: by 2002:a05:622a:1a05:b0:417:953c:ff57 with SMTP id f5-20020a05622a1a0500b00417953cff57mr15066482qtb.14.1698105120076; Mon, 23 Oct 2023 16:52:00 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id dn26-20020a05622a471a00b0040331a24f16sm3097548qtb.3.2023.10.23.16.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 16:51:59 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH v2 3/3] c++: note other candidates when diagnosing deletedness Date: Mon, 23 Oct 2023 19:51:54 -0400 Message-ID: <20231023235154.2971561-3-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.424.gceadf0f3cf In-Reply-To: <20231023235154.2971561-1-ppalka@redhat.com> References: <20231023235154.2971561-1-ppalka@redhat.com> 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.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 List-Id: With the previous two patches in place, we can now extend our deletedness diagnostic to note the other considered candidates, e.g.: 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 For now, these these notes are disabled when a deleted special member function is selected 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 when noting unviability of A(A&&). (It'd be nice if we could downgrade such errors into notes when noting candidates...) 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 | 24 ++++++++++++++++++++++++ 2 files changed, 33 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 3212d5268e0..1313d6516bd 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -9932,7 +9932,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..55acbfd9188 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/deleted16.C @@ -0,0 +1,24 @@ +// 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" } + +// An example where the perfect candidate optimization causes us +// to ignore function templates. +void g(int) = delete; // { dg-message "declared here|candidate" } +template void g(T); // { dg-message "candidate" } + +// An example where we have a strictly viable candidate and +// an incompletely considered bad candidate. +template void h(T, T) = delete; // { dg-message "declared here|candidate" } +void h(int*, int) = delete; // { dg-message "candidate" } + +int main() { + f(0); // { dg-error "deleted" } + g(0); // { dg-error "deleted" } + h(1, 1); // { dg-error "deleted" } + // { dg-error "invalid conversion" "" { target *-*-* } .-1 } when noting 2nd cand +} -- 2.42.0.424.gceadf0f3cf