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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|WONTFIX                     |DUPLICATE
           Severity|normal                      |enhancement

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
Variables that aren't used after they have been assigned to are a indicator of
poor code quality (see CWE-563: Assignment to Variable without Use ('Unused
Variable')).  Issuing a warning for such variables would be not only helpful,
but in my view also consistent with -Wunused-but-set-variable whose documented
purpose is to "Warn whenever a local variable is assigned to, but otherwise
unused (aside from its declaration)."

The semantics of ++m are not the same as m = m + 1 but rather those of m += 1,
with the important (but IMO not relevant to this report) difference of course
being that the left operand is evaluated just once.  Either way, since both of
the latter expressions are forms of assignment (simple vs compound) it's fair
to say that the variable is "assigned to and otherwise unused."  Explaining
this in the documentation shouldn't be difficult, but since these are the
standard semantics that most C and C++ programmers are familiar with, it
doesn't seem that it should be necessary.

I think it's worthwhile to keep this report open, if not as a bug in
-Wunused-but-set-variable then as a enhancement request.

[I was about to reopen it when I noticed Joseph's update so I'm resolving it as
a duplicate instead.]

*** This bug has been marked as a duplicate of bug 44677 ***

Reply via email to