[Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673 --- Comment #4 from Alexey Neyman --- Any chance of this patch getting applied?
[Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673 --- Comment #3 from Marek Polacek mpolacek at gcc dot gnu.org --- The following seems to work and regtests cleanly. But I have to say I'm somewhat dubious now about changing this at all. I suppose I should try to compile e.g. the Linux kernel with this patch and see if anything breaks. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index ebe4c73..590e235 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -7565,7 +7565,7 @@ pop_init_level (location_t loc, int implicit, /* Silently discard empty initializations. The parser will already have pedwarned for empty brackets. */ if (integer_zerop (constructor_unfilled_index)) -constructor_type = NULL_TREE; +/* Do nothing. */; else { gcc_assert (!TYPE_SIZE (constructor_type));
[Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673 Marek Polacek mpolacek at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2015-04-17 CC||mpolacek at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Marek Polacek mpolacek at gcc dot gnu.org --- Confirmed. It seems weird to drop the initializer.
[Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers
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);