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: 50499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2408315wrn; Mon, 30 Jan 2023 13:37:31 -0800 (PST) X-Google-Smtp-Source: AK7set9eWxGTk/U2nzaWE8GuhQ4AdvWWbQ6jP3fYWQpJ/FVtfAlrlpkFwe0DD6Sl5LVNnnaPTxsU X-Received: by 2002:a17:906:2096:b0:878:8249:bef6 with SMTP id 22-20020a170906209600b008788249bef6mr16114755ejq.59.1675114651620; Mon, 30 Jan 2023 13:37:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675114651; cv=none; d=google.com; s=arc-20160816; b=e/ClDohDNMOt59NTr7Wm/qXhPMi3nTKSO/dnimDfkr8GexA0klFb8mM/LNqQ0Vjp9h s3CR5W92s1lZn2TN0LTDflLGppnGMp0FwrUzK2L/xjjZcuZCQrNi8Hg4i1FU2ouISz8T HGxOQBgAfWKri8KcqYcg4058o7rDwycli7Dy3hCSbPP9ta3Dce6hd8PhMaHjbizUGDCY z5HyJjPSb5C17YSx7Uy/cm+/gUJnmHh8Yi49Prm1toEYQyzBHjGsND6eOXamXQevPyA1 YZEKOt6BdJhTW4McPHYzbvaHbQmtrrDBNTwDYbX77LvCUSzPLkkQkgzopcfT1hrhrlE1 xG1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=N2ZdT7bv6TuBscp3B+3YwC+1MSgZJX9soDz66pDI57U=; b=f77xV7KqnfBv9g9UmycVnB9uaXlHZxUS4wONTnoSZJqQqF2zpS7exL3oibQdmnsg0Y sx7/AzSFGxMczYURsDyXDrGhKd29NOx33cym5pb04NTTwOZ8RUAycEhJbujLql4xeUie 0+pjzLtwggVvKHwKRcEGmxSkcbFZy/SWz1dW94NXoyGljNKdiubsquQUVjTp/txPdBSf YYqY5+Ecy8grC5Pl25zE+914uRd7GrTl86Q2aWDnQU0aryie7kwyHi6qRv9XcsAagVy0 wkNq1wLB2dc6R7w5slcQdyyJztw4dF6ODP/r/Jw0RcFk77ikl4u0ChOJaWFVdpnVxIAL scGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Dhgrvn/3"; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f7-20020a1709063f4700b008787fcb4e60si13353425ejj.525.2023.01.30.13.37.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 13:37:31 -0800 (PST) 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=@gcc.gnu.org header.s=default header.b="Dhgrvn/3"; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CAEC3858417 for ; Mon, 30 Jan 2023 21:37:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CAEC3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675114650; 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=Dhgrvn/3E8vQuGvfZzPsYlb/8k9hGBLVwYwe4+b0H5x78AupVZXZPxcFH4xsw8cO1 BFw4/NymKsxbLeKNzttHhTrlULSU0b8p2ByBkdbqviA4Bi3SNUVFJd8fT+/SN9Rluq fPHLioAKRnNTosrLJ3Y3jDPM0/4C9BsHSj6mvWO4= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756485020784922769?= X-GMAIL-MSGID: =?utf-8?q?1756485020784922769?= 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;