summaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index a9f0b9b6ce2..e105f6611c1 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1614,8 +1614,13 @@ reduced_constant_expression_p (tree t)
/* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR. */
tree elt; unsigned HOST_WIDE_INT idx;
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, elt)
- if (!reduced_constant_expression_p (elt))
- return false;
+ {
+ if (!elt)
+ /* We're in the middle of initializing this element. */
+ return false;
+ if (!reduced_constant_expression_p (elt))
+ return false;
+ }
return true;
default:
@@ -2496,8 +2501,16 @@ verify_ctor_sanity (const constexpr_ctx *ctx, tree type)
/* We used to check that ctx->ctor was empty, but that isn't the case when
the object is zero-initialized before calling the constructor. */
if (ctx->object)
- gcc_assert (same_type_ignoring_top_level_qualifiers_p
- (type, TREE_TYPE (ctx->object)));
+ {
+ tree otype = TREE_TYPE (ctx->object);
+ gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, otype)
+ /* Handle flexible array members. */
+ || (TREE_CODE (otype) == ARRAY_TYPE
+ && TYPE_DOMAIN (otype) == NULL_TREE
+ && TREE_CODE (type) == ARRAY_TYPE
+ && (same_type_ignoring_top_level_qualifiers_p
+ (TREE_TYPE (type), TREE_TYPE (otype)))));
+ }
gcc_assert (!ctx->object || !DECL_P (ctx->object)
|| *(ctx->values->get (ctx->object)) == ctx->ctor);
}
@@ -3007,12 +3020,10 @@ cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t,
if (*non_constant_p)
return t;
- /* If we're pulling out the value of an empty base, make sure
- that the whole object is constant and then return an empty
+ /* If we're pulling out the value of an empty base, just return an empty
CONSTRUCTOR. */
if (empty_base && !lval)
{
- VERIFY_CONSTANT (r);
r = build_constructor (TREE_TYPE (t), NULL);
TREE_CONSTANT (r) = true;
}