This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/78964] gcc fails to detect pointless increment
- From: "dcb314 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 02 Jan 2017 07:28:46 +0000
- Subject: [Bug c++/78964] gcc fails to detect pointless increment
- Auto-submitted: auto-generated
- References: <bug-78964-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78964
--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
>Why should it warn?
For all the same reasons as warning -Wunused-but-set-variable.
See the following code:
extern void g( int);
void f( int n)
{
int m = 0;
int m2 = 2;
for (int i = 0; i < n; ++i)
{
g(i);
++m;
}
m2 = 3;
}
$ ~/gcc/results/bin/gcc -c -O2 -Wall jan02.cc
jan02.cc: In function ‘void f(int)’:
jan02.cc:7:6: warning: variable ‘m2’ set but not used
[-Wunused-but-set-variable]
int m2 = 2;
^~
$
The compiler warns about m2, but not m. Anomaly.