cppcheck warns about unused functions (which are used!)
pisanuw opened this issue · comments
Environment
- Operating System (e.g. Ubuntu 16.04 x64): Darwin MAC-30223656 16.7.0 Darwin Kernel Version 16.7.0
- IDE Version (e.g. CLion 2016.3.2): CLion 2018.2.3
- Cppcheck executable version (
cppcheck --version): Cppcheck 1.86 - Cppcheck plugin version: 1.2.0
- Exact strings used in cppcheck plugin options: --enable=all --force --inconclusive --language=c++ --std=c++14 --suppress=missingIncludeSystem
- cppcheck path: /Users/pisan/xxx/bin/cppcheck
- cppcheck options: ?
Expected behaviour
Do not warn about functions that are called
On command line
cppcheck --enable=all --force --inconclusive --language=c++ --std=c++14 --suppress=missingIncludeSystem *.cpp does not give any warnings
Actual behaviour
cppcheck: (style) The function funcFoo is never used warning in CLion right gutter as well as "Code Inspection"
Steps to reproduce the behaviour
main.cpp
#include <iostream>
void funcFoo();
int main() {
funcFoo();
return 0;
}
foo.cpp
void funcFoo() {
}
I also came across this. The command-line will not report the warning since it will scan all files in a single scan and see the usage. In the IDE it will only scan the separate file so it appear unused to it. I think it should use --suppress=unusedFunction for now to avoid this warnings.
I will also take a look at figuring out if this warning could be made a bit smarter - some ideas:
- do not report as unused if only a single file is scanned and it is specified in the header
- if a single file is used only report unused
staticfunctions - do not report unused functions at all when scanning a header
I created a ticket with Cppcheck - see https://trac.cppcheck.net/ticket/9682
There's a similar issue with unusedStructMember warnings in headers - see https://trac.cppcheck.net/ticket/9961
Yes, this is why --enable=unusedFunction is not enabled by default in the plugin. Based on how this plugin runs (one file at a time), these warnings are not displayed correctly in the IDE.
This is causes by the --enable=all flag in your configuration.
Still Cppcheck could be smarter about this. Tickets are filed and hopefully at some point someone will care about it... (possibly me at some point :D)
Until Cppcheck behaves better I would suggest to internally disable these warnings for headers. I already have a patch ready.
I filed another ticket with an idea on how to improve this - see https://trac.cppcheck.net/ticket/10727.
A fix of this bug will be very helpfull