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]

C++ PATCH: PR6438



The evil statement-expression extension strikes again.

Normally, we convert expression-statements to "void".  In other
words, we turn:

  a = c + 3;

into:

  (void)(a = c + 3);

in the C++ front end.  This is somewhat pointless, but we do it to
get certain warnings and such at that point.

However, if we're in a statement-expression it's bad to do this; the
value might be needed.  Fortunately, we have a flag that indicates
that the conversion is being done implicitly, in which case we don't
really do the conversion; we just pretend.

Except that when the expression was a ?:-expression, we did do the
conversion even when we weren't supposed to do so.

Fixed thusly, tested on i686-pc-linux-gnu, applied on the branch
and the mainline.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-04-24  Mark Mitchell  <mark@codesourcery.com>

	* cvt.c (convert_to_void): Don't unconditionally make COND_EXPRs
	void.

Index: gcc/cp/cvt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cvt.c,v
retrieving revision 1.112.2.1
diff -c -p -r1.112.2.1 cvt.c
*** gcc/cp/cvt.c	14 Mar 2002 14:19:51 -0000	1.112.2.1
--- gcc/cp/cvt.c	24 Apr 2002 22:34:43 -0000
*************** convert_to_void (expr, implicit)
*** 836,842 ****
          tree new_op1 = convert_to_void (op1, implicit);
          tree new_op2 = convert_to_void (op2, implicit);
          
! 	expr = build (COND_EXPR, void_type_node,
  		      TREE_OPERAND (expr, 0), new_op1, new_op2);
          break;
        }
--- 836,842 ----
          tree new_op1 = convert_to_void (op1, implicit);
          tree new_op2 = convert_to_void (op2, implicit);
          
! 	expr = build (COND_EXPR, TREE_TYPE (new_op1),
  		      TREE_OPERAND (expr, 0), new_op1, new_op2);
          break;
        }
Index: gcc/testsuite/g++.dg/parse/stmtexpr2.C
===================================================================
RCS file: gcc/testsuite/g++.dg/parse/stmtexpr2.C
diff -N gcc/testsuite/g++.dg/parse/stmtexpr2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/parse/stmtexpr2.C	24 Apr 2002 22:34:43 -0000
***************
*** 0 ****
--- 1,11 ----
+ // { dg-do compile }
+ // { dg-options "" }
+ 
+ #define DMAX(a,b) ({double _a = (a), _b = (b); _a > _b ? _a : _b; })
+ 
+ void foo(void)
+ {
+   double xl, dy;
+   xl = DMAX(dy, 0.0);
+ }
+ 


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