aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-05-10 18:37:56 +0000
committerJason Merrill <jason@redhat.com>2010-05-10 18:37:56 +0000
commitf03ed2416c0583b5a6ef71f11a73e927078c2063 (patch)
treec22516bdca0cac3cfcac3c2e9b60621bf52287c6
parent77ff0a21bb52fcc608cfd11d3f60432ab313e74b (diff)
PR c++/44045
* typeck.c (cp_build_modify_expr): Complain about assignment to array from init list. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@159243 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist26.C2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist28.C2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist33.C13
6 files changed, 34 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c62f817e53a..beedb80edd9 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2010-05-10 Jason Merrill <jason@redhat.com>
+
+ PR c++/44045
+ * typeck.c (cp_build_modify_expr): Complain about assignment to
+ array from init list.
+
2010-05-10 Fabien ChĂȘne <fabien.chene@gmail.com>
PR c++/43719
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 61d5f224cab..5c8fd82688c 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/ChangeLog b/gcc/testsuite/ChangeLog
index 7f76632a802..9f0a4b1d670 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2010-05-10 Jason Merrill <jason@redhat.com>
+
+ PR c++/44045
+ * g++.dg/cpp0x/initlist33.C: New.
+ * g++.dg/cpp0x/initlist26.C: Adjust.
+ * g++.dg/cpp0x/initlist28.C: Adjust.
+
2010-05-10 Fabien ChĂȘne <fabien.chene@gmail.com>
PR c++/43719
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist26.C b/gcc/testsuite/g++.dg/cpp0x/initlist26.C
index 645e74f70dc..bb28bdbd9b3 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 3b959a03a53..d1df7cb0044 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 00000000000..b1c0ba09b5e
--- /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" }
+}