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.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 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=1675114605; 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; bh=N2ZdT7bv6TuBscp3B+3YwC+1MSgZJX9soDz66pDI57U=; b=iPyLMjcJuXjtVbM9TMbN+q6Q7ph7FizQ6lWnBF9Xmb4Xp7zVENnRO8vtnGpKEMRP9czGNv EOulOiS+oVMTt569ieEE5wp7gHpEmVmCV1Dl3W2S//hVBAnybasiwA3lq6FaNt8MZ4/01C +Sva9f+oz5LvxgiQQHfqN9Lj0iCEbwY= 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) From: Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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; -- 2.39.1.367.g5cc9858f1b