Bug 86239 - Suggestion: Improve "set but not used variable" warning
Summary: Suggestion: Improve "set but not used variable" warning
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 8.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
Reported: 2018-06-20 12:11 UTC by some
Modified: 2021-12-20 08:03 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:

compiled with gcc -Wall -Wextra -pedantic (61 bytes, text/plain)
2018-06-20 12:11 UTC, some

Note You need to log in before you can comment on or make changes to this bug.
Description some 2018-06-20 12:11:36 UTC
Created attachment 44304 [details]
compiled with gcc -Wall -Wextra -pedantic


I am not sure if I am right on this, but I noticed that having code like this:

useless = 0;
useless = useless;

silences the set but not used variable warning (assume that useless is a local variable and is not used anywhere else). Now, I would agree that the second line is useless and a terrible thing to do, but still, wouldn't it better if the compiler still complained about the set but not used variable (perhaps about the useless command as well, but I do not know if it would be easy to classify identity/"useless" commands.

I attach a very small file that I used to test the compiler warnings.
Comment 1 Eric Gallager 2021-12-20 08:03:28 UTC
I think there's another bug open about this...