aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-02-20 13:54:45 -0500
committerJason Merrill <jason@gcc.gnu.org>2019-02-20 13:54:45 -0500
commite0737c209bb0a1075201d22d89baa1575c44d153 (patch)
treedd75208166f9718dcc53c90f0a861e6e10669c86 /gcc
parentcb13308543771f56bbc932933b9ec7bbb95d37ac (diff)
downloadgcc-e0737c209bb0a1075201d22d89baa1575c44d153.zip
gcc-e0737c209bb0a1075201d22d89baa1575c44d153.tar.gz
gcc-e0737c209bb0a1075201d22d89baa1575c44d153.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/typeck2.c11
-rw-r--r--gcc/testsuite/g++.dg/ext/flexary33.C13
3 files changed, 25 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 83d3ac9..02e0845 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.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 4e4b1f0..af56632 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 0000000..a12a634
--- /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);