diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2012-11-07 16:58:03 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2012-11-07 16:58:03 +0000 |
commit | 3f46d6a577819e7db2c77fa369d5364afeaac9b0 (patch) | |
tree | 0971d353c36c1931f05e569bcfda7a563741f4f0 | |
parent | dc2d3c67bcc032989d86c9c4637b24157912d34a (diff) | |
download | gcc-3f46d6a577819e7db2c77fa369d5364afeaac9b0.zip gcc-3f46d6a577819e7db2c77fa369d5364afeaac9b0.tar.gz gcc-3f46d6a577819e7db2c77fa369d5364afeaac9b0.tar.bz2 |
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
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr51294.c | 9 |
4 files changed, 27 insertions, 16 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index f7c9422..6f343ef 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +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> PR c++/54930 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 840bc84..90c1992 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2670,22 +2670,14 @@ conversion_warning (tree type, tree expr) case COND_EXPR: { - /* In case of COND_EXPR, if both operands are constants or - COND_EXPR, then we do not care about the type of COND_EXPR, - only about the conversion of each operand. */ - tree op1 = TREE_OPERAND (expr, 1); - tree op2 = TREE_OPERAND (expr, 2); - - if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST - || TREE_CODE (op1) == COND_EXPR) - && (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. */ + /* In case of COND_EXPR, we do not care about the type of + COND_EXPR, only about the conversion of each operand. */ + tree op1 = TREE_OPERAND (expr, 1); + tree op2 = TREE_OPERAND (expr, 2); + + conversion_warning (type, op1); + conversion_warning (type, op2); + return; } default: /* 'expr' is not a constant. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3fb9de45..7c2d5df 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +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> PR tree-optimization/53787 diff --git a/gcc/testsuite/c-c++-common/pr51294.c b/gcc/testsuite/c-c++-common/pr51294.c new file mode 100644 index 0000000..395e6b2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr51294.c @@ -0,0 +1,9 @@ +/* { 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_; +} |