From: Joseph Myers Date: Tue, 3 Dec 2013 02:47:13 +0000 (+0000) Subject: re PR c/58235 (Missing diagnostic on assignment to array in c89) X-Git-Tag: releases/gcc-4.9.0~2321 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c2ecab0e4978f3a4a5b40fe595729b30375386a;p=thirdparty%2Fgcc.git re PR c/58235 (Missing diagnostic on assignment to array in c89) PR c/58235 c: * c-typeck.c (build_modify_expr): Diagnose assignment to expression with array type. testsuite: * gcc.dg/c90-array-lval-8.c: New test. From-SVN: r205615 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index a106e64d094a..42b0bb7db8e1 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2013-12-02 Joseph Myers + + PR c/58235 + * c-typeck.c (build_modify_expr): Diagnose assignment to + expression with array type. + 2013-11-29 Joseph Myers PR c/42262 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 4d701045309a..672a564d2ce9 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -5205,6 +5205,14 @@ build_modify_expr (location_t location, tree lhs, tree lhs_origtype, if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) return error_mark_node; + /* Ensure an error for assigning a non-lvalue array to an array in + C90. */ + if (TREE_CODE (lhstype) == ARRAY_TYPE) + { + error_at (location, "assignment to expression with array type"); + return error_mark_node; + } + /* For ObjC properties, defer this check. */ if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign)) return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c79226b34dfc..f4443d2515ad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-12-02 Joseph Myers + + PR c/58235 + * gcc.dg/c90-array-lval-8.c: New test. + 2013-12-02 Jakub Jelinek PR tree-optimization/59358 diff --git a/gcc/testsuite/gcc.dg/c90-array-lval-8.c b/gcc/testsuite/gcc.dg/c90-array-lval-8.c new file mode 100644 index 000000000000..bc5b7b21b8a5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c90-array-lval-8.c @@ -0,0 +1,20 @@ +/* Test for non-lvalue arrays: test that they cannot be assigned to + array variables. PR 58235. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */ + +struct s { char c[1]; } x; +struct s f (void) { return x; } + +void +g (void) +{ + char c[1]; + c = f ().c; /* { dg-error "array" } */ +} + +void +h (void) +{ + char c[1] = f ().c; /* { dg-error "array" } */ +}