Hi,

On 03/26/2013 04:10 PM, Jason Merrill wrote:
On 03/26/2013 11:00 AM, Paolo Carlini wrote:
+      tree ce_index = cxx_constant_value (ce->index);
+
+      if (TREE_CODE (ce_index) == INTEGER_CST)
+    {
        /* A C99 designator is OK if it matches the current index.  */
-      if (TREE_INT_CST_LOW (ce->index) == index)
+      if (TREE_INT_CST_LOW (ce_index) == index)
          return true;

Hmm, it occurs to me that we probably want to replace ce->index with the constant value for the benefit of varasm. I'm surprised that the testcase passes without doing that.
No problem. The below is already past g++.dg/dg.exp.

Paolo.

/////////////////////////
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 197097)
+++ cp/decl.c   (working copy)
@@ -4760,7 +4760,7 @@ grok_reference_init (tree decl, tree type, tree in
    is valid, i.e., does not have a designated initializer.  */
 
 static bool
-check_array_designated_initializer (const constructor_elt *ce,
+check_array_designated_initializer (constructor_elt *ce,
                                    unsigned HOST_WIDE_INT index)
 {
   /* Designated initializers for array elements are not supported.  */
@@ -4769,10 +4769,22 @@ static bool
       /* The parser only allows identifiers as designated
         initializers.  */
       if (ce->index == error_mark_node)
-       error ("name used in a GNU-style designated "
-              "initializer for an array");
-      else if (TREE_CODE (ce->index) == INTEGER_CST)
        {
+         error ("name used in a GNU-style designated "
+                "initializer for an array");
+         return false;
+       }
+      else if (identifier_p (ce->index))
+       {
+         error ("name %qD used in a GNU-style designated "
+                "initializer for an array", ce->index);
+         return false;
+       }
+
+      ce->index = cxx_constant_value (ce->index);
+
+      if (TREE_CODE (ce->index) == INTEGER_CST)
+       {
          /* A C99 designator is OK if it matches the current index.  */
          if (TREE_INT_CST_LOW (ce->index) == index)
            return true;
@@ -4780,11 +4792,8 @@ static bool
            sorry ("non-trivial designated initializers not supported");
        }
       else
-       {
-         gcc_assert (identifier_p (ce->index));
-         error ("name %qD used in a GNU-style designated "
-                "initializer for an array", ce->index);
-       }
+       gcc_unreachable ();
+
       return false;
     }
 
Index: testsuite/g++.dg/ext/desig5.C
===================================================================
--- testsuite/g++.dg/ext/desig5.C       (revision 0)
+++ testsuite/g++.dg/ext/desig5.C       (working copy)
@@ -0,0 +1,7 @@
+// PR c++/55951
+
+enum { A };
+
+static const char *a[] = {
+  [A] = "a"
+};

Reply via email to