]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/87148
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Mar 2019 18:46:32 +0000 (18:46 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Mar 2019 18:46:32 +0000 (18:46 +0000)
* init.c (build_value_init_noctor): Ignore flexible array members.

* g++.dg/ext/flexary34.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269434 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/flexary34.C [new file with mode: 0644]

index a076fa9a255e92048005fa01b744e7e62f1cbec4..b0c1f88c6a2dbd74313002422d4552818f819c28 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/87148
+       * init.c (build_value_init_noctor): Ignore flexible array members.
+
 2019-03-06  Jason Merrill  <jason@redhat.com>
 
        PR c++/89576 - if constexpr of lambda capture.
index eb3b504d708d7b80b780f7f4c677d26ab629b708..79a93a297a91d76f7ac0c924dc30b3e36d9f7a7d 100644 (file)
@@ -419,6 +419,15 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
              if (ftype == error_mark_node)
                continue;
 
+             /* Ignore flexible array members for value initialization.  */
+             if (TREE_CODE (ftype) == ARRAY_TYPE
+                 && !COMPLETE_TYPE_P (ftype)
+                 && !TYPE_DOMAIN (ftype)
+                 && COMPLETE_TYPE_P (TREE_TYPE (ftype))
+                 && (next_initializable_field (DECL_CHAIN (field))
+                     == NULL_TREE))
+               continue;
+
              /* We could skip vfields and fields of types with
                 user-defined constructors, but I think that won't improve
                 performance at all; it should be simpler in general just
index 9a65e3a81470b2d48ae609d2f96de12ef32cf91f..4175bc4b24676f93022d2aba572768c673199ed9 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/87148
+       * g++.dg/ext/flexary34.C: New test.
+
 2019-03-06  Peter Bergner  <bergner@linux.ibm.com>
 
        PR rtl-optimization/88845
diff --git a/gcc/testsuite/g++.dg/ext/flexary34.C b/gcc/testsuite/g++.dg/ext/flexary34.C
new file mode 100644 (file)
index 0000000..bbbbf85
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/87148
+// { dg-do compile }
+// { dg-options "-pedantic" }
+
+struct Tst { int i; char t[]; };       // { dg-warning "forbids flexible array member" }
+
+Tst t {};                              // { dg-warning "extended initializer lists only available with" "" { target c++98_only } }
+Tst u = Tst();
+void foo () { Tst u = {}; }
+Tst *bar () { return new Tst (); }