diff options
author | Jason Merrill <jason@redhat.com> | 2023-03-17 15:27:10 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-03-17 17:31:36 -0400 |
commit | 890043314a7f405081990ea9d0cb577dd44f883f (patch) | |
tree | 45a0f31590b7a4c253bdbe4a5501a85368965265 /gcc/cp/except.cc | |
parent | c48be8298c27143c1a684c0cb9689c88d16f4b49 (diff) | |
download | gcc-890043314a7f405081990ea9d0cb577dd44f883f.zip gcc-890043314a7f405081990ea9d0cb577dd44f883f.tar.gz gcc-890043314a7f405081990ea9d0cb577dd44f883f.tar.bz2 |
c++: throw and private destructor [PR109172]
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.
Diffstat (limited to 'gcc/cp/except.cc')
-rw-r--r-- | gcc/cp/except.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index 916e818..91a5e04 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); |