Commit 10d2f801 by Jason Merrill Committed by Jason Merrill

PR c++/91369 - constexpr destructor and member initializer.

Previously it didn't matter whether we looked through a TARGET_EXPR in
constexpr evaluation, but now that we have constexpr destructors it does.
On IRC I mentioned the idea of clearing TARGET_EXPR_CLEANUP in
digest_nsdmi_init, but since this initialization is expressed by an
INIT_EXPR, it's better to handle all INIT_EXPR, not just those for a member
initializer.

	* constexpr.c (cxx_eval_store_expression): Look through TARGET_EXPR
	when not preevaluating.

From-SVN: r280018
parent cd3ca6cb
2020-01-08 Jason Merrill <jason@redhat.com> 2020-01-08 Jason Merrill <jason@redhat.com>
PR c++/91369 - constexpr destructor and member initializer.
* constexpr.c (cxx_eval_store_expression): Look through TARGET_EXPR
when not preevaluating.
2020-01-08 Jason Merrill <jason@redhat.com>
* constexpr.c (cxx_eval_call_expression): Remove DECL_BY_REFERENCE * constexpr.c (cxx_eval_call_expression): Remove DECL_BY_REFERENCE
support. support.
......
...@@ -4577,6 +4577,12 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, ...@@ -4577,6 +4577,12 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
} }
new_ctx.ctor = *valp; new_ctx.ctor = *valp;
new_ctx.object = target; new_ctx.object = target;
/* Avoid temporary materialization when initializing from a TARGET_EXPR.
We don't need to mess with AGGR_EXPR_SLOT/VEC_INIT_EXPR_SLOT because
expansion of those trees uses ctx instead. */
if (TREE_CODE (init) == TARGET_EXPR)
if (tree tinit = TARGET_EXPR_INITIAL (init))
init = tinit;
init = cxx_eval_constant_expression (&new_ctx, init, false, init = cxx_eval_constant_expression (&new_ctx, init, false,
non_constant_p, overflow_p); non_constant_p, overflow_p);
if (ctors->is_empty()) if (ctors->is_empty())
......
// PR c++/91369
// { dg-do compile { target c++2a } }
struct S {
constexpr S (int* i) : s{i} {}
constexpr ~S () { delete s; }
int *s;
};
struct T { S t = { new int }; };
constexpr auto
foo ()
{
T b;
return true;
}
static_assert (foo ());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment