PR c++/85136 - ICE with designated init in template.
authorJason Merrill <jason@redhat.com>
Thu, 5 Apr 2018 19:43:39 +0000 (15:43 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 5 Apr 2018 19:43:39 +0000 (15:43 -0400)
* decl.c (maybe_deduce_size_from_array_init): Handle dependent
designated initializer.
(check_array_designated_initializer): Update ce->index with the
constant value.

From-SVN: r259152

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/ext/desig11.C [new file with mode: 0644]

index 7fef0c80b7f98da8455a008bdaac814330a7fb07..2c5e1e25f40367941f6e4b7bd21d706795a594e3 100644 (file)
@@ -1,5 +1,11 @@
 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.
index 489dcc0a8ed9b3b12feef8971180cf406bdbc2ef..86251f51eb4bafb263e314c6a5fc05fe77ca2381 100644 (file)
@@ -5415,12 +5415,15 @@ check_array_designated_initializer (constructor_elt *ce,
                                                  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");
        }
@@ -5463,8 +5466,12 @@ maybe_deduce_size_from_array_init (tree decl, tree init)
          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)
diff --git a/gcc/testsuite/g++.dg/ext/desig11.C b/gcc/testsuite/g++.dg/ext/desig11.C
new file mode 100644 (file)
index 0000000..34bfbe1
--- /dev/null
@@ -0,0 +1,15 @@
+// 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>();
+}