]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: split_nonconstant_init and flexarrays
authorJason Merrill <jason@redhat.com>
Mon, 15 Nov 2021 17:59:08 +0000 (12:59 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 15 Nov 2021 23:48:04 +0000 (18:48 -0500)
split_nonconstant_init was doing the wrong thing for both the initialization
and cleanup here; we know the size from the initializer, and we can pass it
along.  This doesn't make the testcase work, since the y destructor is still
broken, but it removes the wrong error for the aggregate initialization.

gcc/cp/ChangeLog:

* typeck2.c (split_nonconstant_init_1): Handle flexarrays better.

gcc/testsuite/ChangeLog:

* g++.dg/ext/flexary37.C: Remove expected error.

gcc/cp/typeck2.c
gcc/testsuite/g++.dg/ext/flexary37.C

index c01f2f8ced449acf3fd5ebd1f884635d8895823e..e98fbf7f5fa31b5ce44b18af46fc355ff9ebcb61 100644 (file)
@@ -484,6 +484,15 @@ split_nonconstant_init_1 (tree dest, tree init, bool nested)
           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
          || vla_type_p (type))
        {
+         if (!TYPE_DOMAIN (type)
+             && TREE_CODE (init) == CONSTRUCTOR
+             && CONSTRUCTOR_NELTS (init))
+           {
+             /* Flexible array.  */
+             cp_complete_array_type (&type, init, /*default*/true);
+             dest = build1 (VIEW_CONVERT_EXPR, type, dest);
+           }
+
          /* For an array, we only need/want a single cleanup region rather
             than one per element.  */
          tree code = build_vec_init (dest, NULL_TREE, init, false, 1,
index ceb5053de2e15098b6630cdaf7595efb69f9dd67..5cd48c1f773fd543bbd6c076671f32ff9e61aeb9 100644 (file)
@@ -12,4 +12,4 @@ public:
 
 struct y { // { dg-error "unknown array size in delete" }
     int a; C b[];
-} y = { 1, { { 2, 3 } } }; // { dg-error "unknown array size in delete" }
+} y = { 1, { { 2, 3 } } };