This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/44045 (ice on array assignment)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 10 May 2010 14:45:48 -0400
- Subject: C++ PATCH for c++/44045 (ice on array assignment)
We already had a couple of testcases which tested for errors on lines
that involved assignment to an array from an initializer-list, but we
weren't giving an error on this one...and then we crashed in
build_vec_init because it wasn't prepared to deal. Fixed by adding a
specific error for this case.
Tested x86_64-pc-linux-gnu, applied to trunk.
commit b24cb14fd941bea3e262b29d043cc82b96bbeb31
Author: Jason Merrill <jason@redhat.com>
Date: Mon May 10 14:37:22 2010 -0400
PR c++/44045
* typeck.c (cp_build_modify_expr): Complain about assignment to
array from init list.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 61d5f22..5c8fd82 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6634,6 +6634,12 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
if (BRACE_ENCLOSED_INITIALIZER_P (newrhs))
{
+ if (modifycode != INIT_EXPR)
+ {
+ if (complain & tf_error)
+ error ("assigning to an array from an initializer list");
+ return error_mark_node;
+ }
if (check_array_initializer (lhs, lhstype, newrhs))
return error_mark_node;
newrhs = digest_init (lhstype, newrhs);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist26.C b/gcc/testsuite/g++.dg/cpp0x/initlist26.C
index 645e74f..bb28bdb 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist26.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist26.C
@@ -6,5 +6,5 @@ void
foo (int i)
{
int a[i];
- a = { }; // { dg-error "may not be initialized" }
+ a = { }; // { dg-error "assign" }
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist28.C b/gcc/testsuite/g++.dg/cpp0x/initlist28.C
index 3b959a0..d1df7cb 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist28.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist28.C
@@ -4,5 +4,5 @@
void foo()
{
int a[1];
- throw a = {}; // { dg-error "invalid use of non-lvalue array" }
+ throw a = {}; // { dg-error "assign" }
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist33.C b/gcc/testsuite/g++.dg/cpp0x/initlist33.C
new file mode 100644
index 0000000..b1c0ba0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist33.C
@@ -0,0 +1,13 @@
+// PR c++/44045
+// { dg-options "-std=c++0x" }
+
+struct base
+{
+ virtual ~base() { }
+};
+
+int main()
+{
+ base ptr_array[1];
+ ptr_array = { base() }; // { dg-error "assign" }
+}