]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: initialized array of vla [PR58646]
authorJason Merrill <jason@redhat.com>
Mon, 21 Mar 2022 21:48:01 +0000 (17:48 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 21 Mar 2022 22:25:17 +0000 (18:25 -0400)
We went into build_vec_init because we're dealing with a VLA, but then
build_vec_init thought it was safe to just build an INIT_EXPR because the
outer dimension is constant.  Nope.

PR c++/58646

gcc/cp/ChangeLog:

* init.cc (build_vec_init): Check for vla element type.

gcc/testsuite/ChangeLog:

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

gcc/cp/init.cc
gcc/testsuite/g++.dg/ext/vla24.C [new file with mode: 0644]

index 7575597c8fd1075fc90c8c62e0b8e965ab535a4f..08767679dd4410e0d84cfa27f83d4ba9bc4d8a63 100644 (file)
@@ -4395,6 +4395,7 @@ build_vec_init (tree base, tree maxindex, tree init,
   if (init
       && TREE_CODE (atype) == ARRAY_TYPE
       && TREE_CONSTANT (maxindex)
+      && !vla_type_p (type)
       && (from_array == 2
          ? vec_copy_assign_is_trivial (inner_elt_type, init)
          : !TYPE_NEEDS_CONSTRUCTING (type))
diff --git a/gcc/testsuite/g++.dg/ext/vla24.C b/gcc/testsuite/g++.dg/ext/vla24.C
new file mode 100644 (file)
index 0000000..0a99c00
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/58646
+// { dg-additional-options -Wno-vla }
+
+void foo(int n)
+{
+  int a[2][n] = {};
+}