[C++ PATCH] PR c++/88380 - wrong-code with flexible array and NSDMI.
Jason Merrill
jason@redhat.com
Wed Feb 20 19:14:00 GMT 2019
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.
Tested x86_64-pc-linux-gnu, applying to trunk.
* typeck2.c (process_init_constructor_record): Skip flexarrays.
---
gcc/cp/typeck2.c | 11 +++++++----
gcc/testsuite/g++.dg/ext/flexary33.C | 13 +++++++++++++
gcc/cp/ChangeLog | 5 +++++
3 files changed, 25 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/flexary33.C
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);
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 <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>
PR c++/88572 - wrong handling of braces on scalar init.
base-commit: 53ceddc9ed98b8717dc8ae7695459a76f16011cf
--
2.20.1
More information about the Gcc-patches
mailing list