This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C patch to deprecate compound expressions as lvalues
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 6 Nov 2003 23:03:20 +0000 (UTC)
- Subject: C patch to deprecate compound expressions as lvalues
This patch is the third part of deprecating extended lvalues: it
deprecates compound expressions as lvalues (and as a side effect fixes
some cases where compound expressions were wrongly and undocumentedly
treated as constant expressions). While compound expressions as
lvalues may have the least semantic problems, they also most clearly
do not add expressive power ((a, b) = c does simply mean (a, (b = c)))
and adding expressive power is key to justifying the existence of
extensions.
Bootstrapped with no regressions on i686-pc-linux-gnu. I'll apply
this patch soon in the absence of objections to deprecating this
extension. The next stage - removing these extensions altogether -
will of course need to wait until after 3.4 branches.
2003-11-06 Joseph S. Myers <jsm@polyomino.org.uk>
* c-typeck.c (pedantic_lvalue_warning): Deprecate compound
expressions as lvalues.
(internal_build_compound_expr): Remove special handling for
non-pedantic case.
* doc/extend.texi: Document that all extended lvalues are now
deprecated.
2003-11-06 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/compound-lvalue-1.c: New test.
* gcc.dg/c90-const-expr-2.c, gcc.dg/c99-const-expr-2.c: Remove
some XFAILs.
--- GCC/gcc/c-typeck.c.orig 2003-11-05 17:50:29.000000000 +0000
+++ GCC/gcc/c-typeck.c 2003-11-06 19:06:26.000000000 +0000
@@ -2591,8 +2591,7 @@ pedantic_lvalue_warning (enum tree_code
pedwarn ("use of conditional expressions as lvalues is deprecated");
break;
case COMPOUND_EXPR:
- if (pedantic)
- pedwarn ("ISO C forbids use of compound expressions as lvalues");
+ pedwarn ("use of compound expressions as lvalues is deprecated");
break;
default:
pedwarn ("use of cast expressions as lvalues is deprecated");
@@ -2903,11 +2902,6 @@ internal_build_compound_expr (tree list,
&& ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
&& VOID_TYPE_P (TREE_TYPE (TREE_VALUE (list)))))
warning ("left-hand operand of comma expression has no effect");
-
- /* When pedantic, a compound expression can be neither an lvalue
- nor an integer constant expression. */
- if (! pedantic)
- return rest;
}
/* With -Wunused, we should also warn if the left-hand operand does have
--- GCC/gcc/doc/extend.texi.orig 2003-10-27 10:59:49.000000000 +0000
+++ GCC/gcc/doc/extend.texi 2003-11-06 10:25:04.000000000 +0000
@@ -1069,7 +1069,8 @@
Compound expressions, conditional expressions and casts are allowed as
lvalues provided their operands are lvalues. This means that you can take
-their addresses or store values into them.
+their addresses or store values into them. All these extensions are
+deprecated.
Standard C++ allows compound expressions and conditional expressions
as lvalues, and permits casts to reference type, so use of this
--- GCC/gcc/testsuite/gcc.dg/compound-lvalue-1.c 2002-08-26 16:21:36.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/compound-lvalue-1.c 2003-11-06 10:23:08.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test for deprecation of compound expressions as lvalues. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int x, y;
+
+void
+foo (void)
+{
+ (x, y) = 1; /* { dg-warning "lvalue" "compound expression as lvalue deprecated" } */
+}
--- GCC/gcc/testsuite/gcc.dg/c90-const-expr-2.c.orig 2003-10-04 07:36:35.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/c90-const-expr-2.c 2003-11-06 21:40:34.000000000 +0000
@@ -30,7 +30,7 @@
ASSERT_NPC ((void *)0);
ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
- ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
/* This last one is a null pointer constant in C99 only. */
ASSERT_NOT_NPC ((void *)(1 ? 0 : (0, 0))); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
--- GCC/gcc/testsuite/gcc.dg/c99-const-expr-2.c.orig 2003-10-04 07:36:35.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/c99-const-expr-2.c 2003-11-06 21:40:44.000000000 +0000
@@ -30,7 +30,7 @@
ASSERT_NPC ((void *)0);
ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
- ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
/* This last one is a null pointer constant in C99 only. */
ASSERT_NPC ((void *)(1 ? 0 : (0, 0)));
--- changes.html.orig 2003-11-06 10:15:57.000000000 +0000
+++ changes.html 2003-11-06 16:54:52.000000000 +0000
@@ -122,6 +122,15 @@
</pre>
<p>will not be accepted for C and Objective-C in a future
version.</p></li>
+ <li>The compound-expression-as-lvalue extension has been
+ deprecated for C and Objective-C. In particular, code like
+ this:
+ <pre>
+ int a, b;
+ (a, b) = 2;
+ </pre>
+ <p>will not be accepted for C and Objective-C in a future
+ version.</p></li>
</ul>
--
Joseph S. Myers
jsm@polyomino.org.uk