new file mode 100644
@@ -0,0 +1,27 @@
+// { dg-do compile }
+// { dg-require-effective-target c++17 }
+// { dg-options "-O -Wuninitialized" }
+
+#include <optional>
+struct X {
+ X() = default;
+ X(X const& r) : i(r.i) {}
+ int i;
+};
+struct Y {
+ Y() : x() {}
+ X x;
+ std::optional<int> o;
+};
+struct Z {
+ Y y;
+ explicit Z(Y y) : y(y) {}
+};
+void f(Y const&);
+void test() {
+ Y const y;
+ Z z(y);
+ z.y.o = 1;
+ auto const w = z;
+ f(w.y);
+}
@@ -260,6 +260,9 @@ struct access
/* Should TREE_NO_WARNING of a replacement be set? */
unsigned grp_no_warning : 1;
+
+ /* Result of propagation accross link from LHS to RHS. */
+ unsigned grp_result_of_prop_from_lhs : 1;
};
typedef struct access *access_p;
@@ -2532,6 +2535,9 @@ analyze_access_subtree (struct access *root, struct access *parent,
if (allow_replacements && expr_with_var_bounded_array_refs_p (root->expr))
allow_replacements = false;
+ if (!totally && root->grp_result_of_prop_from_lhs)
+ allow_replacements = false;
+
for (child = root->first_child; child; child = child->next_sibling)
{
hole |= covered_to < child->offset;
@@ -2959,6 +2965,7 @@ propagate_subaccesses_from_lhs (struct access *lacc, struct access *racc)
struct access *new_acc
= create_artificial_child_access (racc, lchild, norm_offset,
true, false);
+ new_acc->grp_result_of_prop_from_lhs = 1;
propagate_subaccesses_from_lhs (lchild, new_acc);
}
else