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]

[gcc-in-cxx] Change C++ frontend warning about ?: with no effect


The C++ frontend currently warns about using ?: with no effect based on
whether the other side of the conditional has no effect.  That fails on
macros used by gcc itself, such as this one:

#define EMIT_MODE_SET(ENTITY, MODE, HARD_REGS_LIVE) 			\
  ((MODE) != I387_CW_ANY && (MODE) != I387_CW_UNINITIALIZED		\
   ? emit_i387_cw_initialization (MODE), 0				\
   : 0)

This conditional appears to have a useless "0" on both sides, but that
doesn't mean that the conditional has no effect.  To let this kind of
thing work, I changed the warning to only warn if neither side has an
effect.  I committed this to the gcc-in-cxx branch.

Ian


2009-03-04  Ian Lance Taylor  <iant@google.com>

	* cp/cvt.c (convert_to_void): Only warn about ?: operator with
	no effect if neither side has an effect.

Index: cp/cvt.c
===================================================================
--- cp/cvt.c	(revision 144568)
+++ cp/cvt.c	(working copy)
@@ -807,11 +807,12 @@ convert_to_void (tree expr, const char *
 	/* The two parts of a cond expr might be separate lvalues.  */
 	tree op1 = TREE_OPERAND (expr,1);
 	tree op2 = TREE_OPERAND (expr,2);
+	bool side_effects = TREE_SIDE_EFFECTS (op1) || TREE_SIDE_EFFECTS (op2);
 	tree new_op1 = convert_to_void
-	  (op1, (implicit && !TREE_SIDE_EFFECTS (op2)
+	  (op1, (implicit && !side_effects
 		 ? "second operand of conditional" : NULL), complain);
 	tree new_op2 = convert_to_void
-	  (op2, (implicit && !TREE_SIDE_EFFECTS (op1)
+	  (op2, (implicit && !side_effects
 		 ? "third operand of conditional" : NULL), complain);
 
 	expr = build3 (COND_EXPR, TREE_TYPE (new_op1),

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