From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: throw and private destructor [PR109172]
Date: Fri, 17 Mar 2023 17:32:05 -0400 [thread overview]
Message-ID: <20230317213205.1383604-1-jason@redhat.com> (raw)
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
Since we aren't going through the normal call machinery, we need to check
the dtor access specifically.
PR c++/109172
gcc/cp/ChangeLog:
* except.cc (build_throw): Check dtor access.
gcc/testsuite/ChangeLog:
* g++.dg/eh/dtor4.C: New test.
---
gcc/cp/except.cc | 10 ++++++++--
gcc/testsuite/g++.dg/eh/dtor4.C | 15 +++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/eh/dtor4.C
diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc
index 916e8189db6..91a5e049860 100644
--- a/gcc/cp/except.cc
+++ b/gcc/cp/except.cc
@@ -639,6 +639,8 @@ build_throw (location_t loc, tree exp)
tree object, ptr;
tree allocate_expr;
+ tsubst_flags_t complain = tf_warning_or_error;
+
/* The CLEANUP_TYPE is the internal type of a destructor. */
if (!cleanup_type)
{
@@ -759,11 +761,15 @@ build_throw (location_t loc, tree exp)
cleanup = NULL_TREE;
if (type_build_dtor_call (TREE_TYPE (object)))
{
- tree dtor_fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)),
+ tree binfo = TYPE_BINFO (TREE_TYPE (object));
+ tree dtor_fn = lookup_fnfields (binfo,
complete_dtor_identifier, 0,
tf_warning_or_error);
dtor_fn = BASELINK_FUNCTIONS (dtor_fn);
- mark_used (dtor_fn);
+ if (!mark_used (dtor_fn)
+ || !perform_or_defer_access_check (binfo, dtor_fn,
+ dtor_fn, complain))
+ return error_mark_node;
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (object)))
{
cxx_mark_addressable (dtor_fn);
diff --git a/gcc/testsuite/g++.dg/eh/dtor4.C b/gcc/testsuite/g++.dg/eh/dtor4.C
new file mode 100644
index 00000000000..6c0e804fe8a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/dtor4.C
@@ -0,0 +1,15 @@
+// PR c++/109172
+
+class Demo
+{
+ ~Demo();
+};
+
+int main()
+{
+ try
+ {
+ throw *new Demo; // { dg-error private }
+ }
+ catch(const Demo& e) { }
+}
base-commit: c48be8298c27143c1a684c0cb9689c88d16f4b49
--
2.31.1
reply other threads:[~2023-03-17 21:32 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=20230317213205.1383604-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@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).