* tree.c (vla_type_p): New.
* typeck2.c (store_init_value, split_nonconstant_init_1): Check it
rather than array_of_runtime_bound_p.
From-SVN: r260012
+2018-05-07 Jason Merrill <jason@redhat.com>
+
+ PR c++/85618 - ICE with initialized VLA.
+ * tree.c (vla_type_p): New.
+ * typeck2.c (store_init_value, split_nonconstant_init_1): Check it
+ rather than array_of_runtime_bound_p.
+
2018-05-05 Paolo Carlini <paolo.carlini@oracle.com>
* cvt.c (ocp_convert): Early handle the special case of a
extern tree build_cplus_array_type (tree, tree);
extern tree build_array_of_n_type (tree, int);
extern bool array_of_runtime_bound_p (tree);
+extern bool vla_type_p (tree);
extern tree build_array_copy (tree);
extern tree build_vec_init_expr (tree, tree, tsubst_flags_t);
extern void diagnose_non_constexpr_vec_init (tree);
return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
}
-/* True iff T is an N3639 array of runtime bound (VLA). These were
- approved for C++14 but then removed. */
+/* True iff T is an N3639 array of runtime bound (VLA). These were approved
+ for C++14 but then removed. This should only be used for N3639
+ specifically; code wondering more generally if something is a VLA should use
+ vla_type_p. */
bool
array_of_runtime_bound_p (tree t)
|| (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
}
+/* True iff T is a variable length array. */
+
+bool
+vla_type_p (tree t)
+{
+ for (; t && TREE_CODE (t) == ARRAY_TYPE;
+ t = TREE_TYPE (t))
+ if (tree dom = TYPE_DOMAIN (t))
+ {
+ tree max = TYPE_MAX_VALUE (dom);
+ if (!potential_rvalue_constant_expression (max)
+ || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
+ return true;
+ }
+ return false;
+}
+
/* Return a reference type node referring to TO_TYPE. If RVAL is
true, return an rvalue reference type, otherwise return an lvalue
reference type. If a type node exists, reuse it, otherwise create
array_type_p = true;
if ((TREE_SIDE_EFFECTS (init)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
- || array_of_runtime_bound_p (type))
+ || vla_type_p (type))
{
/* For an array, we only need/want a single cleanup region rather
than one per element. */
will perform the dynamic initialization. */
if (value != error_mark_node
&& (TREE_SIDE_EFFECTS (value)
- || array_of_runtime_bound_p (type)
+ || vla_type_p (type)
|| ! reduced_constant_expression_p (value)))
return split_nonconstant_init (decl, value);
/* If the value is a constant, just put it in DECL_INITIAL. If DECL
--- /dev/null
+// PR c++/85618
+// { dg-additional-options "-Wno-vla" }
+
+ void function(int size) {
+ bool myArray[size][size] = {};
+ }