Package: cppcheck
Version: 1.65-1
Severity: normal
Dear Maintainer,
I checked my program in C++ using the "cppcheck -q --enable=all --template=gcc
../" And I think that I have faced with a false warning.
My function performs a some action when entering the loop - each time except
the first. Boolean variable (flag of first entry) is declared before the cycle
and is initialized to "true" (first entry). It is assigned a "false" (re-entry)
inside the loop. Example:
/* forward.cpp */
int
main()
{
bool first_time = true;
while (true) {
if (first_time) {
first_time = false;
}
else {
// do something
}
}
}
Cppcheck does not detect errors in this code. But my code was written a little
differently, though he worked the same way. My code is:
/* backward.cpp */
int
main()
{
bool first_time = true;
while (true) {
if (not first_time) {
// do something
}
else {
first_time = false;
}
}
}
Output of cppcheck:
backward.cpp:4: style: The scope of the variable 'first_time' can be reduced.
backward.cpp:10: style: Variable 'first_time' is assigned a value that is never
used.
I think that it is wrong, because these two pieces of code perform the same.
Also, if to follow this recommendation of cppcheck, code meaning changes
completely.
I am using Debian GNU/Linux jessie/sid, kernel 3.14-1-686-pae and libc6 2.19-4
Version of cppcheck: 1.65-1
-- System Information:
Debian Release: jessie/sid
APT prefers testing-proposed-updates
APT policy: (500, 'testing-proposed-updates'), (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 3.14-1-686-pae (SMP w/8 CPU cores)
Locale: LANG=ru_UA.UTF-8, LC_CTYPE=ru_UA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages cppcheck depends on:
ii libc6 2.19-4
ii libgcc1 1:4.9.0-7
ii libpcre3 1:8.31-5
ii libstdc++6 4.9.0-7
ii libtinyxml2-2 2.0.2-1
cppcheck recommends no packages.
cppcheck suggests no packages.
-- no debconf information
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]