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