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

Mikhail Maltsev <maltsevm at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maltsevm at gmail dot com

--- Comment #5 from Mikhail Maltsev <maltsevm at gmail dot com> ---
> gets somehow transformed into
> b = (a = 0B) != 0B;, 0;

Probably folding works this way. Anyway, I think, I can explain how the warning
is [not] generated (I stepped through the code using GDB). So:
We start parsing RHS of assignment expression (the outermost one). After
parsing two operands of comma, we get into build_compound_expr function (in
c-typeck.c) and this function generates a warning because "left-hand operand of
comma expression" (i.e. 0) "has no effect" (that's true, but the wording is a
bit strange). Then we parse the next comma expression and get into the same
function. The code of build_compound_expr looks like this:

    ...
  if (!TREE_SIDE_EFFECTS (expr1))
    ...
  else if (TREE_CODE (expr1) == COMPOUND_EXPR && warn_unused_value)
    ...

  /* With -Wunused, we should also warn if the left-hand operand does have
     side-effects, but computes a value which is not used.  For example, in
     `foo() + bar(), baz()' the result of the `+' operator is not used,
     so we should issue a warning.  */
  else if (warn_unused_value)
    warn_if_unused_value (expr1, loc);

Unfortunately, we don't get into warn_if_unused_value because the condition of
previous branch is true. That's why there is no warning about the result of
comparison.

P.S. I know, that it all might be obvious for most of you, but I'm just trying
to get acquainted with GCC sources and (hopefully) do something useful for the
project, while waiting for next stage1 (bugs being fixed during stage 4 are
obviously not for newcomers).

Reply via email to