diff options
author | Jason Merrill <jason@redhat.com> | 2023-12-12 18:07:28 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-05-01 14:59:26 -0400 |
commit | a12cae973900f118436ef85c1197e91bf0428280 (patch) | |
tree | 77887bf5d629fa2afe7305845640bcbb8a61d216 /gcc/cp | |
parent | 76ca6e1f8b1524b82a871ce29cf58c79e5e77e2b (diff) | |
download | gcc-a12cae973900f118436ef85c1197e91bf0428280.zip gcc-a12cae973900f118436ef85c1197e91bf0428280.tar.gz gcc-a12cae973900f118436ef85c1197e91bf0428280.tar.bz2 |
c++: drop in-charge for dtors without vbases
Constructors and destructors use the in-charge parameter to decide whether
they're responsible for recursing into virtual bases. Historically all
destructors had this parameter in order to also distinguish the deleting
destructor. But r151673 in GCC 4.5 changed the deleting destructor to just
call the complete destructor and then operator delete, making the in-charge
parameter no longer relevant for destructors in classes without virtual
bases. Having it causes confusion in constexpr evaluation, which assumes
that clones will have the same parameters as the cloned 'tor.
gcc/cp/ChangeLog:
* cp-tree.h (base_ctor_identifier): Adjust comment.
* call.cc (in_charge_arg_for_name): Abort on deleting dtor.
* decl2.cc (maybe_retrofit_in_chrg): Don't add it for
destructors without vbases, either.
* constexpr.cc (cxx_eval_call_expression): Remove workaround.
gcc/testsuite/ChangeLog:
* g++.dg/debug/dwarf2/array-3.C: No more 'int' for in-chrg parm.
* g++.dg/debug/dwarf2/array-4.C: Likewise.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/call.cc | 4 | ||||
-rw-r--r-- | gcc/cp/constexpr.cc | 20 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 3 | ||||
-rw-r--r-- | gcc/cp/decl2.cc | 12 |
4 files changed, 15 insertions, 24 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index dbdd7c2..7c4ecf0 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -11167,7 +11167,9 @@ in_charge_arg_for_name (tree name) if (name == complete_dtor_identifier) return integer_two_node; else if (name == deleting_dtor_identifier) - return integer_three_node; + /* The deleting dtor should now be handled by + build_delete_destructor_body. */ + gcc_unreachable (); gcc_checking_assert (name == base_dtor_identifier); } diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8078b31..50f799d 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -3243,19 +3243,13 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, ctx->global->put_value (remapped, arg); remapped = DECL_CHAIN (remapped); } - for (; remapped; remapped = TREE_CHAIN (remapped)) - if (DECL_NAME (remapped) == in_charge_identifier) - { - /* FIXME destructors unnecessarily have in-charge parameters - even in classes without vbases, map it to 0 for now. */ - gcc_assert (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fun))); - ctx->global->put_value (remapped, integer_zero_node); - } - else - { - gcc_assert (seen_error ()); - *non_constant_p = true; - } + if (remapped) + { + /* We shouldn't have any parms without args, but fail gracefully + in error recovery. */ + gcc_checking_assert (seen_error ()); + *non_constant_p = true; + } /* Add the RESULT_DECL to the values map, too. */ gcc_assert (!DECL_BY_REFERENCE (res)); ctx->global->put_value (res, NULL_TREE); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1938ada..5d1bd6b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -289,8 +289,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; /* The name of a constructor that does not construct virtual base classes. */ #define base_ctor_identifier cp_global_trees[CPTI_BASE_CTOR_IDENTIFIER] /* The name of a destructor that takes an in-charge parameter to - decide whether or not to destroy virtual base classes and whether - or not to delete the object. */ + decide whether or not to destroy virtual base classes. */ #define dtor_identifier cp_global_trees[CPTI_DTOR_IDENTIFIER] /* The name of a destructor that destroys virtual base classes. */ #define complete_dtor_identifier cp_global_trees[CPTI_COMPLETE_DTOR_IDENTIFIER] diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 806a2a4..b8dc55b 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -275,11 +275,8 @@ build_artificial_parm (tree fn, tree name, tree type) return parm; } -/* Constructors for types with virtual baseclasses need an "in-charge" flag - saying whether this constructor is responsible for initialization of - virtual baseclasses or not. All destructors also need this "in-charge" - flag, which additionally determines whether or not the destructor should - free the memory for the object. +/* 'structors for types with virtual baseclasses need an "in-charge" flag + saying whether this function is responsible for virtual baseclasses or not. This function adds the "in-charge" flag to member function FN if appropriate. It is called from grokclassfn and tsubst. @@ -302,10 +299,9 @@ maybe_retrofit_in_chrg (tree fn) if (processing_template_decl) return; - /* We don't need an in-charge parameter for constructors that don't + /* We don't need an in-charge parameter for 'structors that don't have virtual bases. */ - if (DECL_CONSTRUCTOR_P (fn) - && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn))) + if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn))) return; arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn)); |