diff mbox

C++ PATCH for c++/49216 (problems with new T[1]{})

Message ID 4E949DC6.1030906@redhat.com
State New
Headers show

Commit Message

Jason Merrill Oct. 11, 2011, 7:49 p.m. UTC
This ICE is still a regression in 4.6, so I'm checking in this patch to 
fix it.  Note that after this patch, the code generated for new T[1]{} 
is still wrong, but that isn't a regression.  The value-initialization 
semantics are fixed in 4.7.

Tested x86_64-pc-linux-gnu.
diff mbox

Patch

commit 25a2d664e6a3787cc68e3c41beb12330469ee4a5
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 11 15:22:55 2011 -0400

    	PR c++/49216
    	* init.c (build_vec_init): Avoid crash on new int[1]{}.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 9440c1a..c4bd635 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -3067,8 +3067,9 @@  build_vec_init (tree base, tree maxindex, tree init,
       unsigned HOST_WIDE_INT idx;
       tree field, elt;
       /* Should we try to create a constant initializer?  */
-      bool try_const = (literal_type_p (inner_elt_type)
-			|| TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type));
+      bool try_const = (TREE_CODE (atype) == ARRAY_TYPE
+			&& (literal_type_p (inner_elt_type)
+			    || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type)));
       bool saw_non_const = false;
       bool saw_const = false;
       /* If we're initializing a static array, we want to do static
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-49216.C b/gcc/testsuite/g++.dg/cpp0x/initlist-49216.C
new file mode 100644
index 0000000..4bf6082
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-49216.C
@@ -0,0 +1,6 @@ 
+// PR c++/49216
+// { dg-options -std=c++0x }
+
+int main() {
+  new int[1]{};
+}