]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/87148 (backward compatibility issue to take char [] as incomplet...
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Aug 2019 12:13:40 +0000 (14:13 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:13:40 +0000 (14:13 +0200)
Backported from mainline
2019-03-06  Jakub Jelinek  <jakub@redhat.com>

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

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

From-SVN: r275124

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

index d2d55d5f77781b3a43c4ee3296068445515072a8..735a3640a86973ca7694dc9419e2908465da80a4 100644 (file)
@@ -1,6 +1,11 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/87148
+       * init.c (build_value_init_noctor): Ignore flexible array members.
+
        2019-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/89403
index ec01f6b67760279a8ec47edf5ee83931c7523959..99ae47d10c8d643244fec1406c9882760ea5f233 100644 (file)
@@ -409,6 +409,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 206a617043e4d4092c21eea38c6180e5f00a391e..18693b02603d480c026ece46831aad62b0d24fe9 100644 (file)
@@ -1,6 +1,11 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/87148
+       * g++.dg/ext/flexary34.C: New test.
+
        2019-03-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/89590
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 (); }