* Diagnose array assignment for C90 (PR 58235)
@ 2013-12-03 2:49 Joseph S. Myers
0 siblings, 0 replies; only message in thread
From: Joseph S. Myers @ 2013-12-03 2:49 UTC (permalink / raw)
To: gcc-patches
This patch fixes bug 58235, a corner case with non-lvalue arrays in
C90 where the assignment of a non-lvalue array to an expression with
array type was not diagnosed. A specific check is added for
assignments to arrays (which are never valid).
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied
to mainline.
c:
2013-12-02 Joseph Myers <joseph@codesourcery.com>
PR c/58235
* c-typeck.c (build_modify_expr): Diagnose assignment to
expression with array type.
testsuite:
2013-12-02 Joseph Myers <joseph@codesourcery.com>
PR c/58235
* gcc.dg/c90-array-lval-8.c: New test.
Index: testsuite/gcc.dg/c90-array-lval-8.c
===================================================================
--- testsuite/gcc.dg/c90-array-lval-8.c (revision 0)
+++ testsuite/gcc.dg/c90-array-lval-8.c (revision 0)
@@ -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" } */
+}
Index: c/c-typeck.c
===================================================================
--- c/c-typeck.c (revision 205585)
+++ c/c-typeck.c (working copy)
@@ -5205,6 +5205,14 @@ build_modify_expr (location_t location, tree lhs,
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;
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-12-03 2:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-03 2:49 Diagnose array assignment for C90 (PR 58235) Joseph S. Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).