]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/51294 (spurious warning from -Wconversion in C and C++ in conditional express...
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 7 Nov 2012 16:58:03 +0000 (16:58 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 7 Nov 2012 16:58:03 +0000 (16:58 +0000)
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

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr51294.c [new file with mode: 0644]

index f7c942216bcb2c5a99794b2ff6bbc9067a5f0a94..6f343ef2419a2b7236bbe1fd29d246ace699f986 100644 (file)
@@ -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
index 840bc84c6d245192beef97312065add4f4710981..90c1992129f5dec4b7df81d73963cdad2deb0aaf 100644 (file)
@@ -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.  */
index 3fb9de45bb6d9f7b2e352f9ca45c95e8c7b86731..7c2d5dfa39a9098207a526a86431a2ed0ae1fd44 100644 (file)
@@ -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 (file)
index 0000000..395e6b2
--- /dev/null
@@ -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_;
+}