+2016-03-01 Jason Merrill <jason@redhat.com>
+
+ PR c++/69995
+ * constexpr.c (cxx_eval_call_expression): Unshare arg.
+ (cxx_eval_constant_expression) [DECL_EXPR]: Unshare init.
+ [TARGET_EXPR]: Unshare init.
+
2016-03-01 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/68948
tree oparm = TREE_PURPOSE (bound);
tree arg = TREE_VALUE (bound);
gcc_assert (DECL_NAME (remapped) == DECL_NAME (oparm));
+ /* Don't share a CONSTRUCTOR that might be changed. */
+ arg = unshare_expr (arg);
ctx->values->put (remapped, arg);
bound = TREE_CHAIN (bound);
remapped = DECL_CHAIN (remapped);
init = cxx_eval_constant_expression (ctx, init,
false,
non_constant_p, overflow_p);
+ /* Don't share a CONSTRUCTOR that might be changed. */
+ init = unshare_expr (init);
ctx->values->put (r, init);
}
else if (ctx == &new_ctx)
if (lval)
{
tree slot = TARGET_EXPR_SLOT (t);
+ r = unshare_expr (r);
ctx->values->put (slot, r);
return slot;
}
--- /dev/null
+// PR c++/69995
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ int i;
+};
+
+constexpr int f(A a)
+{
+ ++a.i;
+ return a.i;
+}
+
+constexpr bool g()
+{
+ A a = { 42 };
+ if (f(a) != 43) return false;
+ if (a.i != 42) return false;
+ return true;
+}
+
+#define SA(X) static_assert((X),#X)
+SA(g());
--- /dev/null
+// PR c++/69995
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ int i;
+};
+
+constexpr int f(A a)
+{
+ ++a.i;
+ return a.i;
+}
+
+constexpr bool g()
+{
+ A a = { 42 };
+ A b = a;
+ ++b.i;
+ if (b.i != 43) return false;
+ if (a.i != 42) return false;
+ return true;
+}
+
+#define SA(X) static_assert((X),#X)
+SA(g());