public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44677]  New: Warn for variables incremented but not used
@ 2010-06-26  0:53 jsm28 at gcc dot gnu dot org
  2010-06-28  0:35 ` [Bug c/44677] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 8+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2010-06-26  0:53 UTC (permalink / raw)
  To: gcc-bugs

void
f (void)
{
  int i;
  i = 0;
  i++;
}

seems like something a natural generalization of -Wunused-but-set-variable
should warn for; the value of i is only used as part of an increment of i,
so the definition and all uses of this variable could be safely removed.

For a real example of this, see the variable lang_n_infiles in
gcc.c:process_command (I'm testing a patch that removes that variable
along with other changes).


-- 
           Summary: Warn for variables incremented but not used
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jsm28 at gcc dot gnu dot org


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


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

* [Bug c/44677] Warn for variables incremented but not used
  2010-06-26  0:53 [Bug c/44677] New: Warn for variables incremented but not used jsm28 at gcc dot gnu dot org
@ 2010-06-28  0:35 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-06-28  0:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-06-28 00:34 -------
Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2010-06-28 00:34:58
               date|                            |


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


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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2022-09-19 10:03 ` stormbyte at gmail dot com
@ 2022-12-17 17:58 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108156 has been marked as a duplicate of this bug. ***

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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2022-04-09  0:48 ` eggert at cs dot ucla.edu
@ 2022-09-19 10:03 ` stormbyte at gmail dot com
  2022-12-17 17:58 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: stormbyte at gmail dot com @ 2022-09-19 10:03 UTC (permalink / raw)
  To: gcc-bugs

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

David Manuelda <stormbyte at gmail dot com> changed:

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

--- Comment #14 from David Manuelda <stormbyte at gmail dot com> ---
It is worth to notice that this bug propagates to C++ whenever an object uses
an int that increments but is never used, like the following example:

class Test{
        public:
                Test() { i = 0; i++; }
        private:
                int i;
};

int main(int, char**) {
        Test unused;

        return 0;
}

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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-10-24  6:09 ` pinskia at gcc dot gnu.org
@ 2022-04-09  0:48 ` eggert at cs dot ucla.edu
  2022-09-19 10:03 ` stormbyte at gmail dot com
  2022-12-17 17:58 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: eggert at cs dot ucla.edu @ 2022-04-09  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

eggert at cs dot ucla.edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eggert at cs dot ucla.edu

--- Comment #13 from eggert at cs dot ucla.edu ---
I ran into this issue today on Emacs master, with both += and |=. Clang
correctly diagnosed unused local variables, but GCC did not.

It would be nice if GCC could do at least as well as Clang does.

Here are references to patches I installed into Emacs to fix these issues that
Clang found but GCC did not:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=d9bffa1f3b121085fd8f954eb9446a4a5241c062
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=68bc1446855c86b96d5bc22f819e63358ab250ac

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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
  2020-05-19 17:23 ` msebor at gcc dot gnu.org
  2021-04-21 17:41 ` jsm28 at gcc dot gnu.org
@ 2021-10-24  6:09 ` pinskia at gcc dot gnu.org
  2022-04-09  0:48 ` eggert at cs dot ucla.edu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-24  6:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102909 has been marked as a duplicate of this bug. ***

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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
  2020-05-19 17:23 ` msebor at gcc dot gnu.org
@ 2021-04-21 17:41 ` jsm28 at gcc dot gnu.org
  2021-10-24  6:09 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2021-04-21 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eyalroz1 at gmx dot com

--- Comment #11 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
*** Bug 100184 has been marked as a duplicate of this bug. ***

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

* [Bug c/44677] Warn for variables incremented but not used
       [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
@ 2020-05-19 17:23 ` msebor at gcc dot gnu.org
  2021-04-21 17:41 ` jsm28 at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-19 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2010-06-28 00:34:58         |2020-5-19

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
See pr95217 for other cases to handle (-Wunused-but-set-parameter).  For the
test case there, Clang's static analyzer diagnoses two out of the four cases:

$ cat pr95217.c && clang -S -Wall -Wextra --analyze pr95217.c
void f0 (int *p)
{
  p = 0;           // -Wunused-but-set-parameter (expected)
}

void f1 (int *p)
{
  p += 1;          // missing warning
}

void f2 (int *p)
{
  p = p + 1;       // missing warning
}

void f3 (int *p)
{
  ++p;             // missing warning
}

pr95217.c:8:3: warning: Value stored to 'p' is never read
  p += 1;          // missing warning
  ^    ~
pr95217.c:13:3: warning: Value stored to 'p' is never read
  p = p + 1;       // missing warning
  ^   ~~~~~
2 warnings generated.

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

end of thread, other threads:[~2022-12-17 17:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-26  0:53 [Bug c/44677] New: Warn for variables incremented but not used jsm28 at gcc dot gnu dot org
2010-06-28  0:35 ` [Bug c/44677] " pinskia at gcc dot gnu dot org
     [not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
2020-05-19 17:23 ` msebor at gcc dot gnu.org
2021-04-21 17:41 ` jsm28 at gcc dot gnu.org
2021-10-24  6:09 ` pinskia at gcc dot gnu.org
2022-04-09  0:48 ` eggert at cs dot ucla.edu
2022-09-19 10:03 ` stormbyte at gmail dot com
2022-12-17 17:58 ` pinskia at gcc dot gnu.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).