https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96003

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks for the test case.  In it, the no-warning bit set on the conditional
expression to avoid the warning is cleared before the expression reaches the
warning code.  The culprit seems to be the cp_fold_convert() function called on
the expression: it rebuilds the COND_EXPR but fails to propagate the no-warning
bit.  The change below fixes it but I wouldn't be surprised if this wasn't the
only instance where the no-warning bit might get stripped from an expression.

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 300d959278b..67153e3f484 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8754,6 +8754,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree
type, tree op0)
            arg02 = fold_build1_loc (loc, code, type,
                                 fold_convert_loc (loc,
                                                   TREE_TYPE (op0), arg02));
+         bool nowarn = TREE_NO_WARNING (op0);
          tem = fold_build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg0, 0),
                             arg01, arg02);

@@ -8788,6 +8789,8 @@ fold_unary_loc (location_t loc, enum tree_code code, tree
type, tree op0)
                                      TREE_OPERAND (TREE_OPERAND (tem, 1), 0),
                                      TREE_OPERAND (TREE_OPERAND (tem, 2),
                                                    0)));
+         if (nowarn)
+           TREE_NO_WARNING (tem) = true;
          return tem;
        }
    }

Reply via email to