This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR C++/28989, post-increment of bool is wrongly considered a lvalue


On Mon, 2006-09-18 at 13:42 -0700, Mark Mitchell wrote: 
> Does it work to make lvaluep look through SAVE_EXPRs to the thing saved, 
> instead?

Actually that is the real issue that we are looking through SAVE_EXPRs
when they are not be lvalues as they either references an early
SAVE_EXPRs' value or just a place holder for a rvalue.
This patches changes SAVE_EXPRs to be not lvalues in the function
lvalue_p_1 and it fixes the regression.

OK? Bootstrapped and tested with no regressions.

Thanks,
Andrew Pinski

cp/ChangeLog:
	* tree.c (lvalue_p_1 <case SAVE_EXPR>): SAVE_EXPRs are never
	lvalues.

testsuite/ChangeLog:

	* g++.dg/expr/lval3.C: New test.
	* g++.dg/expr/lval4.C: New test.
Index: testsuite/g++.dg/expr/lval3.C
===================================================================
--- testsuite/g++.dg/expr/lval3.C	(revision 0)
+++ testsuite/g++.dg/expr/lval3.C	(revision 0)
@@ -0,0 +1,9 @@
+// i++ is never an lvalue
+void
+f()
+{
+  bool i = 0;
+  i++ = 3; // { dg-error "" }
+}
+
+
Index: testsuite/g++.dg/expr/lval4.C
===================================================================
--- testsuite/g++.dg/expr/lval4.C	(revision 0)
+++ testsuite/g++.dg/expr/lval4.C	(revision 0)
@@ -0,0 +1,9 @@
+// ++i is always an lvalue
+void
+f()
+{
+  bool i = 0;
+  ++i = 3;
+}
+
+
Index: cp/tree.c
===================================================================
--- cp/tree.c	(revision 117190)
+++ cp/tree.c	(working copy)
@@ -72,11 +72,12 @@ lvalue_p_1 (tree ref,
 
   switch (TREE_CODE (ref))
     {
+    case SAVE_EXPR:
+      return clk_none;
       /* preincrements and predecrements are valid lvals, provided
 	 what they refer to are valid lvals.  */
     case PREINCREMENT_EXPR:
     case PREDECREMENT_EXPR:
-    case SAVE_EXPR:
     case TRY_CATCH_EXPR:
     case WITH_CLEANUP_EXPR:
     case REALPART_EXPR:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]