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 80A9A3858C52 for ; Thu, 2 Feb 2023 22:33:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A9A3858C52 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=1675377197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a6n4BJ8vSD6NeQo1VqN4LYFSSL3eNbDk4GQkSEr/iYY=; b=h+EeOGJZ96oZeWPbUra3g6Wfvgm3M6piA6gYG4sRkIUPogbkyFmEwyjBWvaQD3hwXrn5zx BajdeWYcliqRPlhDmAOjQc71nfHcYEKvYTlMUrpGvQrAzUpqC1zxriX8Qpwmwd72dOdyrk ieS5EkihROsO6oErlCLmy7ZddM+UXqM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-76-gsAkGHLsOXWXJNiG-3cdHg-1; Thu, 02 Feb 2023 17:33:16 -0500 X-MC-Unique: gsAkGHLsOXWXJNiG-3cdHg-1 Received: by mail-qv1-f71.google.com with SMTP id l6-20020ad44446000000b00537721bfd2dso1780377qvt.11 for ; Thu, 02 Feb 2023 14:33:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a6n4BJ8vSD6NeQo1VqN4LYFSSL3eNbDk4GQkSEr/iYY=; b=l1CuHNT9e0qGoNgGUvHsFDrREh0hpkh0hdwQzrGFGCTObcBLOdy91emytJ0fCGcfFC rCQzqs5QU8LTMqPxupNu+ZqqrTjoq32mpskqM+lAMlBl4rS/WX9KLadWGuEYNUSkaM0e vZXd4n6JhqytafMmL8lB1Cnl7jfU7UGimpVxeSs+nhvqceTG2O1W0m/sWwEAbpYTyBde c712BiMbWzRY9K4DCrXojenCMotaBnj0tvjWkjLz/9dm7TGQ91+otStzAKqUz3u5g+YP Eu69nQKfWZRZ1BKlhJUTBrAcppoanpk5xTV+8mDiUdv5FcQ1K46uSMrmSVl+sjV3IFlm soXw== X-Gm-Message-State: AO0yUKUnpI5AWa4ndn66htTPnEMWQL7PN0GeLsyA6CUoscU+uMqQdV4f Iuk+jGGzIKbr6xatiUFz54+vsHvu5PK+Mj6CZgzlK/IFlmH/ja4eH0haeE4FA4FHJK376vMCb+S 13zqK6oD7HXq4R3h7TQ== X-Received: by 2002:ac8:5c94:0:b0:3b7:fb35:9163 with SMTP id r20-20020ac85c94000000b003b7fb359163mr15292226qta.30.1675377194981; Thu, 02 Feb 2023 14:33:14 -0800 (PST) X-Google-Smtp-Source: AK7set97oplM4KTE2ZbZQd95pZffXEQASxyyTY0D+XhSJ2nmtMZcsTuUj5hoTO7h3VGkOfV8LVHd3A== X-Received: by 2002:ac8:5c94:0:b0:3b7:fb35:9163 with SMTP id r20-20020ac85c94000000b003b7fb359163mr15292198qta.30.1675377194641; Thu, 02 Feb 2023 14:33:14 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id f9-20020ac84989000000b003b869f71eedsm375513qtq.66.2023.02.02.14.33.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Feb 2023 14:33:14 -0800 (PST) Message-ID: <26aea260-ef7d-86e1-8e1c-547ed45d9550@redhat.com> Date: Thu, 2 Feb 2023 17:33:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] c++: ICE on unviable/ambiguous constrained dtors [PR96745] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230130213639.2585560-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230130213639.2585560-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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: On 1/30/23 16:36, Patrick Palka wrote: > 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? OK for trunk, this doesn't seem important to backport. > 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;