This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
- From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 17 Apr 2015 13:03:29 +0000
- Subject: [Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
- Auto-submitted: auto-generated
- References: <bug-65673-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
What happens here is that pop_init_level returns error_mark_node because
initializing a zero-length array member with {} is discarded:
7565 /* Silently discard empty initializations. The parser will
7566 already have pedwarned for empty brackets. */
7567 if (integer_zerop (constructor_unfilled_index))
7568 constructor_type = NULL_TREE;
thus ret.value is NULL:
7718 if (ret.value == 0 && constructor_stack == 0)
7719 ret.value = error_mark_node;
7720 return ret;
output_init_element then sees that value == error_mark_node, so it marks the
ctor as erroneous:
8388 if (type == error_mark_node || value == error_mark_node)
8389 {
8390 constructor_erroneous = 1;
8391 return;
8392 }
And because the ctor is erroneous, we don't build a CONSTRUCTOR for it:
7668 if (constructor_erroneous)
7669 ret.value = error_mark_node;
7670 else
7671 {
7672 ret.value = build_constructor (constructor_type,
7673 constructor_elements);