Commit e0737c20 by Jason Merrill Committed by Jason Merrill

PR c++/88380 - wrong-code with flexible array and NSDMI.

Here 'skipped' was set to -1 to force an explicit initializer for 'uninit'
before the initializer for 'initialized', and so we also tried to emit an
explicit initializer for the flexible array, for which build_zero_init
returns error_mark_node.  We should ignore flexarrays even when
skipped < 0.

	* typeck2.c (process_init_constructor_record): Skip flexarrays.

From-SVN: r269046
parent cb133085
2019-02-19 Jason Merrill <jason@redhat.com>
PR c++/88380 - wrong-code with flexible array and NSDMI.
* typeck2.c (process_init_constructor_record): Skip flexarrays.
2019-02-20 will wray <wjwray@gmail.com> 2019-02-20 will wray <wjwray@gmail.com>
PR c++/88572 - wrong handling of braces on scalar init. PR c++/88572 - wrong handling of braces on scalar init.
......
...@@ -1602,12 +1602,15 @@ process_init_constructor_record (tree type, tree init, int nested, int flags, ...@@ -1602,12 +1602,15 @@ process_init_constructor_record (tree type, tree init, int nested, int flags,
else else
return PICFLAG_ERRONEOUS; return PICFLAG_ERRONEOUS;
} }
/* Do nothing for flexible array members since they need not have any
elements. Don't worry about 'skipped' because a flexarray has to
be the last field. */
else if (TREE_CODE (fldtype) == ARRAY_TYPE && !TYPE_DOMAIN (fldtype))
continue;
/* Warn when some struct elements are implicitly initialized /* Warn when some struct elements are implicitly initialized
to zero. However, avoid issuing the warning for flexible to zero. */
array members since they need not have any elements. */ if ((complain & tf_warning)
if ((TREE_CODE (fldtype) != ARRAY_TYPE || TYPE_DOMAIN (fldtype))
&& (complain & tf_warning)
&& !EMPTY_CONSTRUCTOR_P (init)) && !EMPTY_CONSTRUCTOR_P (init))
warning (OPT_Wmissing_field_initializers, warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field); "missing initializer for member %qD", field);
......
// PR c++/88380
// { dg-do compile { target c++14 } }
// { dg-options "" }
struct S {
char uninit;
char initialised = 11;
char variable[];
};
constexpr S p {};
#define SA(X) static_assert((X),#X)
SA(p.initialised == 11);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment