Commit d96e8407 by Jason Merrill Committed by Jason Merrill

re PR c++/67364 ("accessing uninitialized member" error in constexpr context)

	PR c++/67364
	* constexpr.c (cxx_eval_store_expression): Replace
	CONSTRUCTOR_ELTS in nested CONSTRUCTORs, too.

From-SVN: r234013
parent 260e910b
2016-03-05 Jason Merrill <jason@redhat.com>
PR c++/67364
* constexpr.c (cxx_eval_store_expression): Replace
CONSTRUCTOR_ELTS in nested CONSTRUCTORs, too.
2016-03-05 Patrick Palka <ppalka@gcc.gnu.org> 2016-03-05 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/66786 PR c++/66786
......
...@@ -2939,9 +2939,9 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, ...@@ -2939,9 +2939,9 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
/* Don't share a CONSTRUCTOR that might be changed later. */ /* Don't share a CONSTRUCTOR that might be changed later. */
init = unshare_expr (init); init = unshare_expr (init);
if (target == object) if (target == object)
{
/* The hash table might have moved since the get earlier. */ /* The hash table might have moved since the get earlier. */
valp = ctx->values->get (object); valp = ctx->values->get (object);
if (TREE_CODE (init) == CONSTRUCTOR) if (TREE_CODE (init) == CONSTRUCTOR)
{ {
/* An outer ctx->ctor might be pointing to *valp, so replace /* An outer ctx->ctor might be pointing to *valp, so replace
...@@ -2952,13 +2952,9 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, ...@@ -2952,13 +2952,9 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
} }
else else
*valp = init; *valp = init;
}
else
{
*valp = init;
/* Update TREE_CONSTANT and TREE_SIDE_EFFECTS on enclosing /* Update TREE_CONSTANT and TREE_SIDE_EFFECTS on enclosing
CONSTRUCTORs. */ CONSTRUCTORs, if any. */
tree elt; tree elt;
unsigned i; unsigned i;
bool c = TREE_CONSTANT (init); bool c = TREE_CONSTANT (init);
...@@ -2971,7 +2967,6 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, ...@@ -2971,7 +2967,6 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
if (s) if (s)
TREE_SIDE_EFFECTS (elt) = true; TREE_SIDE_EFFECTS (elt) = true;
} }
}
release_tree_vector (ctors); release_tree_vector (ctors);
if (*non_constant_p) if (*non_constant_p)
......
// PR c++/67364
// { dg-do compile { target c++11 } }
template <typename Xn>
struct tuple {
Xn storage_;
constexpr tuple(Xn const& xn)
: storage_(xn)
{ }
template <typename ...dummy>
constexpr tuple(tuple const& other)
: storage_(other.storage_)
{ }
template <typename ...dummy>
constexpr tuple(tuple& other)
: tuple(const_cast<tuple const&>(other))
{ }
};
template <typename T>
struct wrapper { T value; };
template <typename T>
constexpr wrapper<T> wrap(T t) { return {t}; }
constexpr wrapper<tuple<int>> t = wrap(tuple<int>{2});
static_assert(t.value.storage_ == 2, "");
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