From patchwork Fri Oct 27 19:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1856444 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=P1OA7Kdz; 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 4SHD7y4BZ3z23k3 for ; Sat, 28 Oct 2023 07:01:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8659D386193A for ; Fri, 27 Oct 2023 20:01:32 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 826B0385351D for ; Fri, 27 Oct 2023 20:01:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 826B0385351D 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 826B0385351D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698436880; cv=none; b=Q+RmIPHav5Ff2txr7Av2LANcly7cF9BKYXHAaFkvoVoj7qEooQU2eGcNr47gs7zmuxeGs/BlX4BXoefzpA8zyI3gYTifVztb0Di/8Ia99YlKQ9XfwHmL/qQio5COWCqWnwzqBfz3p7W47UfZF8bfSZQ9sZt/LgcPstHv78zd3jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698436880; c=relaxed/simple; bh=IYjLemf7tjHa/q+QyLx+Fal9fOB4b2eBaYvTef2XaZc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ys5/NAlAjdUf1g+PTMWRsRiA0lmObj0ubqapvIu8n9gtcdTFpRf5m8UD/Fi+6PUESvvPnXDYMfY33CzplHRB1dG8qlW7DyOwhtVdndo1GTnAdIIuJ5Any0uUanjlw3YBiffq0whBbUcbrAFunVhVy11xN96CfU7is9ig7OvVI9I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698436878; 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=parwmu7mjl0KWvdWrhOzVg9u1mtMk3fV8FAgZtuI+DY=; b=P1OA7KdzbJjBFVKltekPxdJxHS9yY9TXw7/TqSeoplRWUQup8GIy9nVeyFXYGFDT7TFtss Bsv8Wiz/ilS5sVf4zaHymlwBl/MENA5SekeFo77weD0wq1sjGdYnbBi5JcuRYyGu7rgLw4 yZo8t6qI44ijhAETXS64xlUn+kC078Y= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-5AGsRO9IPImuA2s9jpP6uQ-1; Fri, 27 Oct 2023 16:01:16 -0400 X-MC-Unique: 5AGsRO9IPImuA2s9jpP6uQ-1 Received: by mail-vk1-f197.google.com with SMTP id 71dfb90a1353d-49a94be026dso918892e0c.1 for ; Fri, 27 Oct 2023 13:01:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698436875; x=1699041675; 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=parwmu7mjl0KWvdWrhOzVg9u1mtMk3fV8FAgZtuI+DY=; b=KoQtvkjYf3DnN9JOasHSGzJ2rLNGu8GJHk4TMZkXxK+ARAO/Z4Qqu4bi13x/7hjQha N0uHpawfvA2zJeh0TkF/alVdlKrkmwN9Sp1I5hMN/XN2b9DotNvwedrLPaC7IAzr3lSz LLcpRKhH/7dY+5H7W+rDEj/FqexofdxerFWjBYFznSt5ci9sAoyxxnJo2BlLymdZH+jp qx+h4ahhLEK/KGi6ULV24K8/FHOu2iobuS6YYwfB3gfhOUCQACfI7F4lQIgh2/OPjhM/ NcOXMTTbW4hA9akw6SC5Ur8oT/Bqg0K2aX1Cl7qt9toX4uzLEyz6B1nQKdJv/rGEsOfz G33Q== X-Gm-Message-State: AOJu0Yx/GIgduejYnvJSaXNIQ+Fi0s7xVD0vunUk2K8DHrzPM56g4eHN 3SoQXQOtHzoyi6qbK0B9kdDW0w20tnqWo2ozr5D2IZPnNd7Vp31m/HSviEP8SEixnTEn17hbbDQ DUT6UfBDcZ3cCQetqBWAjNbN5f4AXAIgg0dfnHzwOIynKqKxjz93DPPBbKqVeUfiKWU7wqnSGA4 k= X-Received: by 2002:a1f:f2ce:0:b0:49d:92e0:9cd1 with SMTP id q197-20020a1ff2ce000000b0049d92e09cd1mr4022627vkh.11.1698436875480; Fri, 27 Oct 2023 13:01:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5Acodemw6nFg1Oc63TxM/XSB8CLzkrpmwbOKAy85oVdbAMBYFKej89uB5Hrc33tSddRJSQQ== X-Received: by 2002:a1f:f2ce:0:b0:49d:92e0:9cd1 with SMTP id q197-20020a1ff2ce000000b0049d92e09cd1mr4022589vkh.11.1698436875068; Fri, 27 Oct 2023 13:01:15 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id l20-20020a0ce514000000b0065b17b925d0sm910777qvm.38.2023.10.27.13.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 13:01:13 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH v3 3/3] c++: note other candidates when diagnosing deletedness Date: Fri, 27 Oct 2023 15:55:31 -0400 Message-ID: <20231027195532.2566822-3-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.482.g2e8e77cbac In-Reply-To: <20231027195532.2566822-1-ppalka@redhat.com> References: <20231027195532.2566822-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_H3, 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 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 These notes are controlled by a new command line flag -fnote-all-cands, which also controls whether we note ignored candidates more generally. gcc/ChangeLog: * doc/invoke.texi (C++ Dialect Options): Document -fnote-all-cands. gcc/c-family/ChangeLog: * c.opt: Add -fnote-all-cands. gcc/cp/ChangeLog: * call.cc (print_z_candidates): Only print ignored candidates when -fnote-all-cands is set. (build_over_call): When diagnosing deletedness, call print_z_candidates if -fnote-all-cands is set. gcc/testsuite/ChangeLog: * g++.dg/overload/error6.C: Pass -fnote-all-cands. * g++.dg/cpp0x/deleted16.C: New test. --- gcc/c-family/c.opt | 4 ++++ gcc/cp/call.cc | 8 +++++++- gcc/doc/invoke.texi | 5 +++++ gcc/testsuite/g++.dg/cpp0x/deleted16.C | 25 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/overload/error6.C | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/deleted16.C diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 44b9c862c14..a76f73cc661 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2006,6 +2006,10 @@ fnil-receivers ObjC ObjC++ Var(flag_nil_receivers) Init(1) Assume that receivers of Objective-C messages may be nil. +fnote-all-cands +C++ ObjC++ Var(flag_note_all_cands) +Note all candidates during overload resolution failure. + flocal-ivars ObjC ObjC++ Var(flag_local_ivars) Init(1) Allow access to instance variables as if they were local declarations within instance method implementations. diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 81cc029dddb..7ace0e65096 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -4090,6 +4090,8 @@ print_z_candidates (location_t loc, struct z_candidate *candidates, { if (only_viable_p.is_true () && candidates->viable != 1) break; + if (ignored_candidate_p (candidates) && !flag_note_all_cands) + break; print_z_candidate (loc, N_("candidate:"), candidates); } } @@ -9933,7 +9935,11 @@ 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); + if (cand->next && flag_note_all_cands) + print_z_candidates (input_location, cand, /*only_viable_p=*/false); + } return error_mark_node; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5a9284d635c..ac82299416c 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3479,6 +3479,11 @@ Disable built-in declarations of functions that are not mandated by ANSI/ISO C@. These include @code{ffs}, @code{alloca}, @code{_exit}, @code{index}, @code{bzero}, @code{conjf}, and other related functions. +@opindex fnote-all-cands +@item -fnote-all-cands +Permit the C++ front end to note all candidates during overload resolution +failure, including when a deleted function is selected. + @opindex fnothrow-opt @item -fnothrow-opt Treat a @code{throw()} exception specification as if it were a diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted16.C b/gcc/testsuite/g++.dg/cpp0x/deleted16.C new file mode 100644 index 00000000000..506caae76b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/deleted16.C @@ -0,0 +1,25 @@ +// Verify -fnote-all-cands causes us to note other candidates when a deleted +// function is selected by overload resolution. +// { dg-do compile { target c++11 } } +// { dg-additional-options "-fnote-all-cands" } + +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 +} diff --git a/gcc/testsuite/g++.dg/overload/error6.C b/gcc/testsuite/g++.dg/overload/error6.C index 86a12eaa8de..ac513824887 100644 --- a/gcc/testsuite/g++.dg/overload/error6.C +++ b/gcc/testsuite/g++.dg/overload/error6.C @@ -1,5 +1,6 @@ // Verify we note even non-template candidates when diagnosing // overload resolution failure for a template-id. +// { dg-additional-options "-fnote-all-cands" } template void f(T); // { dg-message "candidate" } void f(int); // { dg-message {candidate: 'void f\(int\)' \(ignored\)} }