re PR c/51294 (spurious warning from -Wconversion in C and C++ in conditional expressions)

2012-11-07  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/51294
c-family/
	* c-common.c (conversion_warning): Handle conditional expressions.
testsuite/
	* c-c++-common/pr51294.c: New.

From-SVN: r193301
parent dc2d3c67
2012-11-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/51294
* c-common.c (conversion_warning): Handle conditional expressions.
2012-10-29 Jonathan Wakely <jwakely.gcc@gmail.com> 2012-10-29 Jonathan Wakely <jwakely.gcc@gmail.com>
PR c++/54930 PR c++/54930
......
...@@ -2670,22 +2670,14 @@ conversion_warning (tree type, tree expr) ...@@ -2670,22 +2670,14 @@ conversion_warning (tree type, tree expr)
case COND_EXPR: case COND_EXPR:
{ {
/* In case of COND_EXPR, if both operands are constants or /* In case of COND_EXPR, we do not care about the type of
COND_EXPR, then we do not care about the type of COND_EXPR, COND_EXPR, only about the conversion of each operand. */
only about the conversion of each operand. */ tree op1 = TREE_OPERAND (expr, 1);
tree op1 = TREE_OPERAND (expr, 1); tree op2 = TREE_OPERAND (expr, 2);
tree op2 = TREE_OPERAND (expr, 2);
conversion_warning (type, op1);
if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST conversion_warning (type, op2);
|| TREE_CODE (op1) == COND_EXPR) return;
&& (TREE_CODE (op2) == REAL_CST || TREE_CODE (op2) == INTEGER_CST
|| TREE_CODE (op2) == COND_EXPR))
{
conversion_warning (type, op1);
conversion_warning (type, op2);
return;
}
/* Fall through. */
} }
default: /* 'expr' is not a constant. */ default: /* 'expr' is not a constant. */
......
2012-11-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/51294
* c-c++-common/pr51294.c: New.
2012-11-07 Martin Jambor <mjambor@suse.cz> 2012-11-07 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/53787 PR tree-optimization/53787
......
/* { dg-do compile } */
/* { dg-options "-Wconversion -Wsign-conversion" } */
void foo(int haveBar, char bar_)
{
char zuul = haveBar?bar_:0;
char zuul2 = haveBar?bar_:bar_;
char zuul3 = haveBar?0:bar_;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment