Skip to content

Instantly share code, notes, and snippets.

@ronen
Last active May 16, 2018 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronen/e3cdeb966adc89bc7087b0145f0e19ca to your computer and use it in GitHub Desktop.
Save ronen/e3cdeb966adc89bc7087b0145f0e19ca to your computer and use it in GitHub Desktop.
cppcheck false positive unused Function
#include <functional>
#include <iostream>
int foo() { return 12345; } // FALSE POSITIVE: unusedFunction
int bar(std::function<int()> func) { return func(); }
class A {
public:
A() : a(bar([] { return foo(); })) {}
const int a;
};
int main() {
std::cout << A().a << std::endl; // Correctly prints 12345
}
@ronen
Copy link
Author

ronen commented May 16, 2018

$ c++ --std=c++14 bug.cpp && ./a.out
12345
$ cppcheck --std=c++14 --enable=all false-positive-unusedFunction.cpp
Checking bug.cpp ...
[bug.cpp:4]: (style) The function 'foo' is never used.
(information) Cppcheck cannot find all the include files (use --check-config for details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment