This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch/RFC] PR 55951
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 26 Mar 2013 16:00:08 +0100
- Subject: Re: [C++ Patch/RFC] PR 55951
- References: <51519007 dot 9010708 at oracle dot com> <51519560 dot 8080306 at redhat dot com> <51519FF8 dot 7040500 at oracle dot com> <5151AD4D dot 705 at redhat dot com> <5151AD84 dot 9060400 at redhat dot com>
Hi,
On 03/26/2013 03:15 PM, Jason Merrill wrote:
On 03/26/2013 10:14 AM, Jason Merrill wrote:
On 03/26/2013 09:17 AM, Paolo Carlini wrote:
+ if (identifier_p (ce->index))
+ {
+ error ("name %qD used in a GNU-style designated "
+ "initializer for an array", ce->index);
+ return false;
+ }
+
+ tree ce_index = cxx_constant_value (ce->index);
+
/* 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");
Let's also combine these two instances of the same error.
Or at any rate move the error_mark_node case above cxx_constant_value
as well.
Indeed. Thus I'm finishing testing the below.
Thanks,
Paolo.
////////////////////
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 197097)
+++ cp/decl.c (working copy)
@@ -4769,22 +4769,31 @@ check_array_designated_initializer (const construc
/* 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;
+ }
+
+ 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;
else
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"
+};