2018-04-05 Jason Merrill <jason@redhat.com>
+ PR c++/85136 - ICE with designated init in template.
+ * decl.c (maybe_deduce_size_from_array_init): Handle dependent
+ designated initializer.
+ (check_array_designated_initializer): Update ce->index with the
+ constant value.
+
PR c++/83808 - ICE with VLA initialization.
* typeck2.c (process_init_constructor_array): Don't require a VLA
initializer to have VLA type.
ce->index, true);
if (ce_index
&& INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
- && (TREE_CODE (ce_index = maybe_constant_value (ce_index))
+ && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
== INTEGER_CST))
{
/* A C99 designator is OK if it matches the current index. */
if (wi::to_wide (ce_index) == index)
- return true;
+ {
+ ce->index = ce_index;
+ return true;
+ }
else
sorry ("non-trivial designated initializers not supported");
}
constructor_elt *ce;
HOST_WIDE_INT i;
FOR_EACH_VEC_SAFE_ELT (v, i, ce)
- if (!check_array_designated_initializer (ce, i))
- failure = 1;
+ {
+ if (instantiation_dependent_expression_p (ce->index))
+ return;
+ if (!check_array_designated_initializer (ce, i))
+ failure = 1;
+ }
}
if (failure)
--- /dev/null
+// PR c++/85136
+// { dg-options "" }
+
+enum { e };
+
+template<int I> void f()
+{
+ const int x[] = { [e] = 0 };
+ const int y[] = { [I] = 0 };
+}
+
+int main()
+{
+ f<0>();
+}