public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "maltsevm at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/64639] false negative of -Wunused-value
Date: Tue, 20 Jan 2015 09:32:00 -0000	[thread overview]
Message-ID: <bug-64639-4-MPEpyLZ7YL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-64639-4@http.gcc.gnu.org/bugzilla/>

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).


  parent reply	other threads:[~2015-01-20  9:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-17  7:48 [Bug c/64639] New: " chengniansun at gmail dot com
2015-01-17  8:15 ` [Bug c/64639] " chengniansun at gmail dot com
2015-01-17 18:53 ` chengniansun at gmail dot com
2015-01-18 13:29 ` manu at gcc dot gnu.org
2015-01-20  9:32 ` maltsevm at gmail dot com [this message]
2020-05-19 17:19 ` [Bug c/64639] missing warning by -Wunused-value in compound expressions msebor at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-64639-4-MPEpyLZ7YL@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).