This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/52106] warning for useless assignments
- From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 03 Feb 2012 13:28:39 +0000
- Subject: [Bug c/52106] warning for useless assignments
- Auto-submitted: auto-generated
- References: <bug-52106-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106
Vincent LefÃvre <vincent-gcc at vinc17 dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
Summary|missing |warning for useless
|-Wunused-but-set-variable |assignments
|warning with the a = b = |
|... construct |
--- Comment #2 from Vincent LefÃvre <vincent-gcc at vinc17 dot net> 2012-02-03 13:28:39 UTC ---
Then there should be another warning. So, this is a request for a warning for
assignments that are obviously useless (thus maybe a typo in the code or old
code that could be removed...). It should cover variables set but not used
outside the full expression where they are set. The code
int foo (void)
{
int a, b;
a = b = 0;
return a;
}
gives an example. It could be written:
int foo (void)
{
int a;
a = 0;
return a;
}
"a = b = ...;" is generally used as a shortcut for "a = ...; b = ...;", and if
it isn't (because the behavior would be different at compile time or at run
time), there should be a warning against this construct.