public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ 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] 9+ 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 ` [Bug c/44677] Warn for variables incremented but not used 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
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ 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] 9+ 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 ` [Bug c/44677] Warn for variables incremented but not used 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
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ 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] 9+ 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
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ 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] 9+ 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
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ 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] 9+ 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
2022-12-17 18:04 ` [Bug c/44677] Warn for variables incremented but not used (+=, ++) pinskia at gcc dot gnu.org
2023-07-18 22:59 ` vincent-gcc at vinc17 dot net
7 siblings, 0 replies; 9+ 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] 9+ messages in thread
* [Bug c/44677] Warn for variables incremented but not used (+=, ++)
[not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2022-12-17 17:58 ` pinskia at gcc dot gnu.org
@ 2022-12-17 18:04 ` pinskia at gcc dot gnu.org
2023-07-18 22:59 ` vincent-gcc at vinc17 dot net
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 18:04 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
----------------------------------------------------------------------------
Summary|Warn for variables |Warn for variables
|incremented but not used |incremented but not used
| |(+=, ++)
--- Comment #16 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
"set but not used" (just for future searches)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/44677] Warn for variables incremented but not used (+=, ++)
[not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2022-12-17 18:04 ` [Bug c/44677] Warn for variables incremented but not used (+=, ++) pinskia at gcc dot gnu.org
@ 2023-07-18 22:59 ` vincent-gcc at vinc17 dot net
7 siblings, 0 replies; 9+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-07-18 22:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44677
Vincent Lefèvre <vincent-gcc at vinc17 dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vincent-gcc at vinc17 dot net
--- Comment #17 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Martin Sebor from comment #10)
> $ cat pr95217.c && clang -S -Wall -Wextra --analyze pr95217.c
[...]
> 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.
Clang (15 and above) with -Wunused-but-set-variable now detects the issue on
the "p++" and "p += 1" forms (ditto with other combined assignment operators),
but not on "p = p + 1".
Such forms (p++, etc.) are common, so that detecting an unused variable is very
useful.
Like Paul did for Emacs (comment 13), I've just fixed two issues in GNU MPFR
(one cosmetic about a useless loop variable and one important in the
testsuite), found with Clang 16. The references:
https://gitlab.inria.fr/mpfr/mpfr/-/commit/4c110cf4773b3c07de2a33acbee591cedb083c80
https://gitlab.inria.fr/mpfr/mpfr/-/commit/b34d867fa41934d12d0d4dbaaa0242d6d3eb32c7
For the second MPFR issue, there was an "err++" for each error found by the
function in the testsuite, but err was not tested at the end, so that potential
errors were never reported.
^ permalink raw reply [flat|nested] 9+ 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; 9+ 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] 9+ messages in thread
end of thread, other threads:[~2023-07-18 22:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-44677-4@http.gcc.gnu.org/bugzilla/>
2020-05-19 17:23 ` [Bug c/44677] Warn for variables incremented but not used 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
2022-12-17 18:04 ` [Bug c/44677] Warn for variables incremented but not used (+=, ++) pinskia at gcc dot gnu.org
2023-07-18 22:59 ` vincent-gcc at vinc17 dot net
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
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).