public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case
@ 2005-07-28 17:27 trt at acm dot org
  2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: trt at acm dot org @ 2005-07-28 17:27 UTC (permalink / raw)
  To: gcc-bugs

The following program, compiled with gcc -Wunused, issues no warnings

  int foo (void);
   
  void
  bar (int *p)
  {
     *p++;  /* perhaps (*p)++ was intended? */
     foo () + foo ();
     foo () + foo (), foo ();
  }

(gcc 2.9.6 issues warnings for all three lines)
I have found *p++; to be a fairly common error.
When sizeof(*p) == 1 or (*p)++ is illegal this is usually a superfluous `*',
but otherwise it is quite often a real bug and so there should be a warning.

I don't care much about things like 3+foo(), but mention them
because of this inoperative comment in c-typeck.c

  /* 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.  */

It looks like this code in stmt.c needs yet more tweaking:

    maybe_warn:
      /* If this is an expression with side effects, don't warn.  */
      if (TREE_SIDE_EFFECTS (exp))
        return 0;

-- 
           Summary: The -Wunused (value computed is not used) option missed
                    an important case
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: trt at acm dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2005-08-06 13:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
2005-07-28 22:46   ` Neil Booth
2005-07-28 19:32 ` trt at acm dot org
2005-07-28 22:48 ` neil at daikokuya dot co dot uk
2005-07-28 23:44 ` bangerth at dealii dot org
2005-07-29  0:14 ` [Bug c/23113] [3.4/4.0/4.1 regression] " bangerth at dealii dot org
2005-07-29  5:58 ` pinskia at gcc dot gnu dot org
2005-08-01  0:44 ` jsm28 at gcc dot gnu dot org
2005-08-01 16:48 ` trt at acm dot org
2005-08-02  6:14 ` pinskia at gcc dot gnu dot org
2005-08-02  6:26 ` pinskia at gcc dot gnu dot org
2005-08-03  2:21 ` pinskia at gcc dot gnu dot org
2005-08-06 11:32 ` cvs-commit at gcc dot gnu dot org
2005-08-06 13:35 ` pinskia at gcc dot gnu dot org

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