From patchwork Mon Jan 30 21:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1734459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=khXe2ryR; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P5M2v0THvz1yhq for ; Tue, 31 Jan 2023 08:37:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A4963858C36 for ; Mon, 30 Jan 2023 21:37:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A4963858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675114626; bh=N2ZdT7bv6TuBscp3B+3YwC+1MSgZJX9soDz66pDI57U=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=khXe2ryRzNE3OavyjMwF5ClgSPWemfEmr+GqK102rM1G/w34598hgdAoHSJPffgw+ LwHYKXHrRFjxCElxN/XdDGUHsaLS4TwaxlrUq69lHJoOd/JaY2j3MkVDSLw/I9w7Qw dNaT66KjM/vqVgIO1/wRTw09wHbZ4Ug3pOPlPmD0= 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 2035E3858D1E for ; Mon, 30 Jan 2023 21:36:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2035E3858D1E Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-436-_DBul_ZUMK2H4dfqTd8r9w-1; Mon, 30 Jan 2023 16:36:42 -0500 X-MC-Unique: _DBul_ZUMK2H4dfqTd8r9w-1 Received: by mail-qk1-f197.google.com with SMTP id h13-20020a05620a244d00b006fb713618b8so7856882qkn.0 for ; Mon, 30 Jan 2023 13:36:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=N2ZdT7bv6TuBscp3B+3YwC+1MSgZJX9soDz66pDI57U=; b=Ietz7P327XAFXFGPjYmPtq0vv/qmcVdRM+hsE+FaCwX/jEi484vkFde/YayJwvi/xg ClKAVJ/lBvYJK+ney3nBB9/0wJrU7uzogsGgC/BPhtitqnsFPxRmR77RR8cPUJ/sf8hl 4CBd6iGx9XlfTHnLKkTbNyT+HFXEMhB57FNtm/TX8C9ZHopcsSiplP1s2y7b7eHIm8cz /8YobO5fvNXE6ci++BTJNkXYvDPYSguhAyzr8BwP4gVA9HNDmjEHCEIzZs1yrXJiDnCv bELk6x2bDdam/thRc/xmsfs3Yy9eYIUcyASLPTQ/CQZtVKMOrbgjCZ6jTvGHCLttFNqx C3iA== X-Gm-Message-State: AO0yUKV5j3t8HVTudJKb0aC/RJAmS/dgOpg5bcvVuPRFv9dmIGawfOjj XBehCPyZD0fc16WIoJOgouAzCJrJPMoklKKwn7AcRkEWoqovuVz7pOQZ/ZzV2xDs36s8bcsift2 m0QMVhidGCQl9QeI9T3OeHB3mT8TqOXdxQaPkfSFpx9UTcCzFc+HZPYg2h5ONc0hfFoI= X-Received: by 2002:ac8:580d:0:b0:3b8:41f4:94f8 with SMTP id g13-20020ac8580d000000b003b841f494f8mr15712715qtg.49.1675114601620; Mon, 30 Jan 2023 13:36:41 -0800 (PST) X-Google-Smtp-Source: AK7set+LWyPOEwzyzP6kuQfGoudTQAfg+WR/KI1lmYC/qzbSETY5XUNGx3FcrR+pXp4iAcZ6+VIW8g== X-Received: by 2002:ac8:580d:0:b0:3b8:41f4:94f8 with SMTP id g13-20020ac8580d000000b003b841f494f8mr15712682qtg.49.1675114601293; Mon, 30 Jan 2023 13:36:41 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u20-20020a05620a455400b006fef157c8aesm8787527qkp.36.2023.01.30.13.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 13:36:40 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: ICE on unviable/ambiguous constrained dtors [PR96745] Date: Mon, 30 Jan 2023 16:36:39 -0500 Message-Id: <20230130213639.2585560-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.1.367.g5cc9858f1b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here we're crashing from check_bases_and_members due to CLASSTYPE_DESTRUCTOR being an OVERLOAD which, due to the pruning performed by add_method, should only happen if there is no viable destructor or the destructor is ambiguous. This patch fixes this by making check_bases_and_members naturally handle CLASSTYPE_DESTRUCTOR being an OVERLOAD. It's then convenient to prune the OVERLOAD after diagnosing the inevitable OR failure in check_methods. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 12? PR c++/96745 gcc/cp/ChangeLog: * class.cc (check_methods): Diagnose an unviable OVERLOAD set for CLASSTYPE_DESTRUCTOR differently from an ambiguous one. Then prune the OVERLOAD to a single function. (check_bases_and_members): Handle CLASSTYPE_DESTRUCTOR being an OVERLOAD when calling deduce_noexcept_on_destructor. Document why it has to be called before check_methods. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-dtor1.C: New test. --- gcc/cp/class.cc | 22 ++++++++++++++++++--- gcc/testsuite/g++.dg/cpp2a/concepts-dtor1.C | 18 +++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-dtor1.C diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index d3ce8532d56..c6878cba2ae 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -4808,9 +4808,23 @@ check_methods (tree t) in that class with an empty argument list to select the destructor for the class, also known as the selected destructor. The program is ill-formed if overload resolution fails. */ + int viable = 0; + for (tree fn : ovl_range (dtor)) + if (constraints_satisfied_p (fn)) + ++viable; + gcc_checking_assert (viable != 1); + auto_diagnostic_group d; - error_at (location_of (t), "destructor for %qT is ambiguous", t); + if (viable == 0) + error_at (location_of (t), "no viable destructor for %qT", t); + else + error_at (location_of (t), "destructor for %qT is ambiguous", t); print_candidates (dtor); + + /* Arbitrarily prune the overload set to a single function for + sake of error recovery. */ + tree *slot = find_member_slot (t, dtor_identifier); + *slot = get_first_fn (dtor); } else if (user_provided_p (dtor)) TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true; @@ -6048,10 +6062,12 @@ check_bases_and_members (tree t) check_bases (t, &cant_have_const_ctor, &no_const_asn_ref); /* Deduce noexcept on destructor. This needs to happen after we've set - triviality flags appropriately for our bases. */ + triviality flags appropriately for our bases, and before checking + overriden virtual functions via check_methods. */ if (cxx_dialect >= cxx11) if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) - deduce_noexcept_on_destructor (dtor); + for (tree fn : ovl_range (dtor)) + deduce_noexcept_on_destructor (fn); /* Check all the method declarations. */ check_methods (t); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-dtor1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-dtor1.C new file mode 100644 index 00000000000..b1f3b4e579f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-dtor1.C @@ -0,0 +1,18 @@ +// PR c++/96745 +// { dg-do compile { target c++20 } } + +template +struct A { // { dg-error "destructor for 'A' is ambiguous" } + ~A() requires true; + ~A() requires (!!true); +}; + +A a; + +template +struct B { // { dg-error "no viable destructor for 'B'" } + ~B() requires false; + ~B() requires (!!false); +}; + +B b;