public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6863] c++: deleted fn and noexcept inst [PR101532, PR104225]
Date: Tue, 25 Jan 2022 20:05:01 +0000 (GMT)	[thread overview]
Message-ID: <20220125200501.1F93F385AC33@sourceware.org> (raw)

https://gcc.gnu.org/g:bc90dd0ecf02e11d47d1af7f627e2e2acaa40106

commit r12-6863-gbc90dd0ecf02e11d47d1af7f627e2e2acaa40106
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jan 25 15:04:49 2022 -0500

    c++: deleted fn and noexcept inst [PR101532, PR104225]
    
    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 synthesized noexcept specifier which then only
    silently fails because get_defaulted_eh_spec suppresses diagnostics
    for deleted functions.  This lack of diagnostics causes us to crash on
    the first testcase below (thanks to the assert in finish_expr_stmt), and
    silently accept the second testcase.
    
    To fix this, this patch makes mark_used avoid attempting to instantiate
    the noexcept specifier of a deleted function, so that we'll instead
    directly reject (and diagnose) the function due to its deletedness.
    
            PR c++/101532
            PR c++/104225
    
    gcc/cp/ChangeLog:
    
            * decl2.cc (mark_used): Don't consider maybe_instantiate_noexcept
            on a deleted function.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/nsdmi-template21.C: New test.
            * g++.dg/cpp0x/nsdmi-template21a.C: New test.

Diff:
---
 gcc/cp/decl2.cc                                |  1 +
 gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C  |  8 ++++++++
 gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C | 10 ++++++++++
 3 files changed, 19 insertions(+)

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..79d43a54153
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C
@@ -0,0 +1,8 @@
+// PR c++/101532
+// { dg-do compile { target c++11 } }
+
+struct A { private: ~A(); };
+
+template<class> struct B { A a = A(); }; // { dg-error "private" }
+
+B<int> b; // { dg-error "deleted" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C
new file mode 100644
index 00000000000..08fd37b8035
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C
@@ -0,0 +1,10 @@
+// PR c++/104225
+// { dg-do compile { target c++11 } }
+
+struct A { private: ~A(); };
+
+template<class> struct B { A a = A(); }; // { dg-error "private" }
+
+int main() {
+  new B<int>; // { dg-error "deleted" }
+}


                 reply	other threads:[~2022-01-25 20:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125200501.1F93F385AC33@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).