https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61867
Bug ID: 61867
Summary: gcc can't detect obviously false test
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dcb314 at hotmail dot com
I just tried the following code on trunk 20140720
extern int g(int);
void f( int n)
{
int i;
i = g( n) & 0x02;
if (i == 1)
g( 2);
}
$ ~/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra -pedantic -ansi jul21a.cc
$
so gcc has nothing to say about it. Here is cppcheck, a static analyser,
finding the problem
$ ~/cppcheck/trunk/cppcheck --enable=all jul21a.cc
Checking jul21a.cc...
[jul21a.cc:8] -> [jul21a.cc:10]: (style) Mismatching assignment and comparison,
comparison 'i==1' is always false.
$
I note that about six bugs in the linux kernel and about 40 bugs in
Fedora Linux would be detected by implementing this fix.