Message ID | 20220125170818.1898984-1-ppalka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5379385BF85 for <patchwork@sourceware.org>; Tue, 25 Jan 2022 17:08:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5379385BF85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643130534; bh=PDYgDkCI64znHQozPy207/VmA2W8Ghil+9UUvgG9WjY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DpI4bfwNCyx1ou5+FlHkeDnNS4qIogpmOf7MLS3cpm48IfQrlObG5B1Img7PEZugH yldu27pYK7GQHgKpWjww/WCq6yofWrF2EuC/XBOV2y3LhkMqVwD5oUN4dOZ4Aphi9/ XrHK1nKp35IlXMgqx197/fQCBGcpsA08hxLqxv7o= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 357163858400 for <gcc-patches@gcc.gnu.org>; Tue, 25 Jan 2022 17:08:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 357163858400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-J4bokJOEP0GyPXiXoKeN8A-1; Tue, 25 Jan 2022 12:08:23 -0500 X-MC-Unique: J4bokJOEP0GyPXiXoKeN8A-1 Received: by mail-qk1-f200.google.com with SMTP id u9-20020ae9c009000000b0049ae89c924aso143203qkk.9 for <gcc-patches@gcc.gnu.org>; Tue, 25 Jan 2022 09:08:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PDYgDkCI64znHQozPy207/VmA2W8Ghil+9UUvgG9WjY=; b=nC2FpsFusX+fcgNh3y7ujPAWjNvFaNd2FyCQNceci0NCgiYfCo9wUj9h7QOj/l9VDb jYDIcuMjeI8OktDDgxZyTiFr0cRhL9e8Zt0m6MAhDIJluGkFiCeeLIpL5XygVDb3OzsC NkV3I7cNj6W9AauSj+6nff40V+gYeon6lydpMQLLC6PoyTX8kV3lub4zcG876F/PB31x fuLWnrHfhgSBIl/OaNtrXU6bAJIXjImXT7YKBpmANB+rF0eNoIiFqQ8K3Arr18ff5zQD +c0kqcytvr51lnQbenAs/nKkOGc4vOD6/z6FGGdWQnyjQ6uP4LAvAp6zOtK5iSgXYQZR nD1A== X-Gm-Message-State: AOAM533w6eU2cQ2mX8Opu9uC8HBSCawpX97dlUmpQytOa6NHjpRHwsax CQsLWNsUENx44IJ50GBg7m4VS8nt7PBEUYuHTD+BJcsQuj0lkoPB95raDRbM6vYMr0PeVGtjqbD DK59JFZQDJpmFkz0DJP/S5F3ZQSN4+bLmemYE09AKe8EIIf3T8KN2e2ZRhfW7+p7uhL4= X-Received: by 2002:a05:6214:2465:: with SMTP id im5mr10138271qvb.111.1643130502008; Tue, 25 Jan 2022 09:08:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf72y39XDb8GjC6uTfkvedYCRG1wDuph/UHGhqW9Kt8lLDIG9Wc+FpkJXRbuGdM+ho4Jpfog== X-Received: by 2002:a05:6214:2465:: with SMTP id im5mr10138222qvb.111.1643130501543; Tue, 25 Jan 2022 09:08:21 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id h10sm9817791qko.90.2022.01.25.09.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 09:08:20 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: deleted fn and noexcept inst [PR101532, PR104225] Date: Tue, 25 Jan 2022 12:08:18 -0500 Message-Id: <20220125170818.1898984-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.0 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-Spam-Status: No, score=-14.4 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: deleted fn and noexcept inst [PR101532, PR104225]
|
|
Commit Message
Patrick Palka
Jan. 25, 2022, 5:08 p.m. UTC
Here when attempting to use B's implicitly deleted default constructor, mark_used rightfully returns false, but for the wrong reason: it tries to instantiate the implicit noexcept specifier, which only silently fails because get_defaulted_eh_spec suppresses diagnostics for deleted functions. This causes us to ICE on the first testcase (thanks to the sanity check in finish_expr_stmt) and accept the second invalid testcase without complaint. To fix this, this patch makes mark_used avoid attempting to instantiate the noexcept specifier on a deleted function, so that mark_used will instead directly reject (and diagnose) such a function due to its deletedness. Bootstrap and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/101532 PR c++/104225 gcc/cp/ChangeLog: * decl2.cc (mark_used): Don't call with maybe_instantiate_noexcept on a deleted function. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template21.C: New test. * g++.dg/cpp0x/nsdmi-template22.C: New test. --- gcc/cp/decl2.cc | 1 + gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C | 10 ++++++++++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C | 12 ++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C
Comments
On Tue, 25 Jan 2022, Patrick Palka wrote: > Here when attempting to use B's implicitly deleted default constructor, > mark_used rightfully returns false, but for the wrong reason: it > tries to instantiate the implicit noexcept specifier, which only > silently fails because get_defaulted_eh_spec suppresses diagnostics > for deleted functions. This causes us to ICE on the first testcase > (thanks to the sanity check in finish_expr_stmt) and accept the second > invalid testcase without complaint. > > To fix this, this patch makes mark_used avoid attempting to instantiate > the noexcept specifier on a deleted function, so that mark_used will > instead directly reject (and diagnose) such a function due to its > deletedness. > > Bootstrap and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? ... and perhaps release branches given that the second PR is a regression relative to GCC 8? > > PR c++/101532 > PR c++/104225 > > gcc/cp/ChangeLog: > > * decl2.cc (mark_used): Don't call with > maybe_instantiate_noexcept on a deleted function. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/nsdmi-template21.C: New test. > * g++.dg/cpp0x/nsdmi-template22.C: New test. > --- > gcc/cp/decl2.cc | 1 + > gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C | 10 ++++++++++ > gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C | 12 ++++++++++++ > 3 files changed, 23 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C > create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C > > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc > index 69b97449eac..b68cf96fa81 100644 > --- a/gcc/cp/decl2.cc > +++ b/gcc/cp/decl2.cc > @@ -5774,6 +5774,7 @@ mark_used (tree decl, tsubst_flags_t complain) > used_types_insert (DECL_CONTEXT (decl)); > > if (TREE_CODE (decl) == FUNCTION_DECL > + && !DECL_DELETED_FN (decl) > && !maybe_instantiate_noexcept (decl, complain)) > return false; > > diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C > new file mode 100644 > index 00000000000..b9d4f4a4b9a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C > @@ -0,0 +1,10 @@ > +// PR c++/101532 > +// { dg-do compile { target c++11 } } > + > +class A { ~A(); }; > + > +template<class> class B { // { dg-error "private" } > + A f = A(); > +}; > + > +B<int> b; // { dg-error "deleted" } > diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C > new file mode 100644 > index 00000000000..bbcc7d9732e > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C > @@ -0,0 +1,12 @@ > +// PR c++/104225 > +// { dg-do compile { target c++11 } } > + > +class A { ~A(); }; > + > +template<class> class B { // { dg-error "private" } > + A f = A(); > +}; > + > +int main() { > + new B<int>; // { dg-error "deleted" } > +} > -- > 2.35.0 > >
On 1/25/22 12:33, Patrick Palka wrote: > On Tue, 25 Jan 2022, Patrick Palka wrote: > >> Here when attempting to use B's implicitly deleted default constructor, >> mark_used rightfully returns false, but for the wrong reason: it >> tries to instantiate the implicit noexcept specifier, which only >> silently fails because get_defaulted_eh_spec suppresses diagnostics >> for deleted functions. This causes us to ICE on the first testcase >> (thanks to the sanity check in finish_expr_stmt) and accept the second >> invalid testcase without complaint. >> >> To fix this, this patch makes mark_used avoid attempting to instantiate >> the noexcept specifier on a deleted function, so that mark_used will >> instead directly reject (and diagnose) such a function due to its >> deletedness. >> >> Bootstrap and regtested on x86_64-pc-linux-gnu, does this look OK for >> trunk? > > ... and perhaps release branches given that the second PR is a > regression relative to GCC 8? OK for trunk and release branches. >> >> PR c++/101532 >> PR c++/104225 >> >> gcc/cp/ChangeLog: >> >> * decl2.cc (mark_used): Don't call with >> maybe_instantiate_noexcept on a deleted function. >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/cpp0x/nsdmi-template21.C: New test. >> * g++.dg/cpp0x/nsdmi-template22.C: New test. >> --- >> gcc/cp/decl2.cc | 1 + >> gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C | 10 ++++++++++ >> gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C | 12 ++++++++++++ >> 3 files changed, 23 insertions(+) >> create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C >> create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C >> >> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc >> index 69b97449eac..b68cf96fa81 100644 >> --- a/gcc/cp/decl2.cc >> +++ b/gcc/cp/decl2.cc >> @@ -5774,6 +5774,7 @@ mark_used (tree decl, tsubst_flags_t complain) >> used_types_insert (DECL_CONTEXT (decl)); >> >> if (TREE_CODE (decl) == FUNCTION_DECL >> + && !DECL_DELETED_FN (decl) >> && !maybe_instantiate_noexcept (decl, complain)) >> return false; >> >> diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C >> new file mode 100644 >> index 00000000000..b9d4f4a4b9a >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C >> @@ -0,0 +1,10 @@ >> +// PR c++/101532 >> +// { dg-do compile { target c++11 } } >> + >> +class A { ~A(); }; >> + >> +template<class> class B { // { dg-error "private" } >> + A f = A(); >> +}; >> + >> +B<int> b; // { dg-error "deleted" } >> diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C >> new file mode 100644 >> index 00000000000..bbcc7d9732e >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C >> @@ -0,0 +1,12 @@ >> +// PR c++/104225 >> +// { dg-do compile { target c++11 } } >> + >> +class A { ~A(); }; >> + >> +template<class> class B { // { dg-error "private" } >> + A f = A(); >> +}; >> + >> +int main() { >> + new B<int>; // { dg-error "deleted" } >> +} >> -- >> 2.35.0 >> >> >
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 69b97449eac..b68cf96fa81 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -5774,6 +5774,7 @@ mark_used (tree decl, tsubst_flags_t complain) used_types_insert (DECL_CONTEXT (decl)); if (TREE_CODE (decl) == FUNCTION_DECL + && !DECL_DELETED_FN (decl) && !maybe_instantiate_noexcept (decl, complain)) return false; diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C new file mode 100644 index 00000000000..b9d4f4a4b9a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C @@ -0,0 +1,10 @@ +// PR c++/101532 +// { dg-do compile { target c++11 } } + +class A { ~A(); }; + +template<class> class B { // { dg-error "private" } + A f = A(); +}; + +B<int> b; // { dg-error "deleted" } diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C new file mode 100644 index 00000000000..bbcc7d9732e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C @@ -0,0 +1,12 @@ +// PR c++/104225 +// { dg-do compile { target c++11 } } + +class A { ~A(); }; + +template<class> class B { // { dg-error "private" } + A f = A(); +}; + +int main() { + new B<int>; // { dg-error "deleted" } +}