Hi!

In this PR, Jonathan argues that we should accept value initialization of
classes with flexible array member.

The following patch does that.  Bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?

2019-03-05  Jakub Jelinek  <ja...@redhat.com>

        PR c++/87148
        * init.c (build_value_init_noctor): Ignore flexible array members.

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

--- gcc/cp/init.c.jj    2019-03-05 15:34:17.164490227 +0100
+++ gcc/cp/init.c       2019-03-05 15:34:27.140327205 +0100
@@ -419,6 +419,15 @@ build_value_init_noctor (tree type, tsub
              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
--- gcc/testsuite/g++.dg/ext/flexary34.C.jj     2019-03-05 15:31:38.731079324 
+0100
+++ gcc/testsuite/g++.dg/ext/flexary34.C        2019-03-05 15:32:46.852966084 
+0100
@@ -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 (); }

        Jakub

Reply via email to