$ ./cppcheck --enable=all fp_variableScope.cpp
Checking fp_variableScope.cpp ...
[fp_variableScope.cpp:3]: (style) The scope of the variable 'nbOccurences' can be reduced.
[fp_variableScope.cpp:1]: (style) The function'f' is never used.
Last edit: versat 2018-05-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
$ g++ -fsyntax-only fp_variableScope.cpp
$ ./cppcheck --enable=all fp_variableScope.cpp
Checking fp_variableScope.cpp ...
[fp_variableScope.cpp:6]: (style) The scope of the variable 'nbOccurences' can be reduced.
[fp_variableScope.cpp:4]: (style) The function'f' is never used.
(information) Cppcheck cannot find all the include files (use --check-config for details)
This really seems to be a false positive.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm using CppCheck 1.83, and I get the variableScope message on this piece
of code :
The error occurs on "nbOccurences" variable, which I don't see how to
reduce scope without breaking the functionnal.
Is this a false positive ?
Thanks,
S. Gallou
Last edit: Sébastien Gallou 2018-05-02
Can you please edit the post and add code formatting syntax, for example:
Otherwise some characters can get wrongly interpreted which results in a wrong source code.
Last edit: versat 2018-05-02
Yes, you're right.
Done.
If i use exactly your source code i do not get a false positive with Cppcheck 1.83 or current development version.
If the code is inside a function then i do get the variableScope message:
Last edit: versat 2018-05-03
I tried to reduce the code so it does not use boost and does not error out via
g++ -fsyntax-only
.For this code:
Cppcheck reports the following:
This really seems to be a false positive.
I created the ticket 8541 for this issue.
Thanks a lot, I will follow it.