static void
maybe_push_temp_cleanup (tree sub, vec<tree,va_gc> **flags)
{
+ if (!flag_exceptions)
+ return;
if (tree cleanup
= cxx_maybe_build_cleanup (sub, tf_warning_or_error))
{
bool array_type_p = false;
bool complete_p = true;
HOST_WIDE_INT num_split_elts = 0;
+ tree last_split_elt = NULL_TREE;
switch (TREE_CODE (type))
{
else
{
/* Mark element for removal. */
+ last_split_elt = field_index;
CONSTRUCTOR_ELT (init, idx)->index = NULL_TREE;
if (idx < tidx)
tidx = idx;
flags));
/* Mark element for removal. */
+ last_split_elt = field_index;
CONSTRUCTOR_ELT (init, idx)->index = NULL_TREE;
if (idx < tidx)
tidx = idx;
{
tree code;
+ /* Push cleanups for any preceding members with constant
+ initialization. */
+ if (CLASS_TYPE_P (type))
+ for (tree prev = (last_split_elt ?
+ DECL_CHAIN (last_split_elt)
+ : TYPE_FIELDS (type));
+ ; prev = DECL_CHAIN (prev))
+ {
+ prev = next_initializable_field (prev);
+ if (prev == field_index)
+ break;
+ tree ptype = TREE_TYPE (prev);
+ if (type_build_dtor_call (ptype))
+ {
+ tree pcref = build3 (COMPONENT_REF, ptype, dest, prev,
+ NULL_TREE);
+ maybe_push_temp_cleanup (pcref, flags);
+ }
+ }
+
/* Mark element for removal. */
CONSTRUCTOR_ELT (init, idx)->index = NULL_TREE;
if (idx < tidx)
maybe_push_temp_cleanup (sub, flags);
}
+ last_split_elt = field_index;
num_split_elts++;
}
}
--- /dev/null
+// PR c++/96876
+// { dg-do compile { target c++17 } }
+
+struct B {
+protected:
+ ~B() {} // { dg-message "" }
+};
+
+struct A { };
+struct C1: B { int n; };
+struct C2: A, B { int n; };
+
+A af ();
+int f();
+
+void g() {
+ C1 c1{ {}, f()}; // { dg-error "protected" }
+ C2 c2{ af(), {}, f()}; // { dg-error "protected" }
+}