From e0737c209bb0a1075201d22d89baa1575c44d153 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 20 Feb 2019 13:54:45 -0500 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck2.c | 11 +++++++---- gcc/testsuite/g++.dg/ext/flexary33.C | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/flexary33.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 83d3ac94039..02e0845f1d7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-02-19 Jason Merrill + + PR c++/88380 - wrong-code with flexible array and NSDMI. + * typeck2.c (process_init_constructor_record): Skip flexarrays. + 2019-02-20 will wray PR c++/88572 - wrong handling of braces on scalar init. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 4e4b1f03b7c..af56632c0fc 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1602,12 +1602,15 @@ process_init_constructor_record (tree type, tree init, int nested, int flags, else 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 - to zero. However, avoid issuing the warning for flexible - array members since they need not have any elements. */ - if ((TREE_CODE (fldtype) != ARRAY_TYPE || TYPE_DOMAIN (fldtype)) - && (complain & tf_warning) + to zero. */ + if ((complain & tf_warning) && !EMPTY_CONSTRUCTOR_P (init)) warning (OPT_Wmissing_field_initializers, "missing initializer for member %qD", field); diff --git a/gcc/testsuite/g++.dg/ext/flexary33.C b/gcc/testsuite/g++.dg/ext/flexary33.C new file mode 100644 index 00000000000..a12a6349621 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary33.C @@ -0,0 +1,13 @@ +// 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); -- 2.30.2