Why is this an issue?
A function that is never called is dead code, and should be removed. Cleaning out dead code decreases the size of the maintained codebase, making
it easier to understand the program and preventing bugs from being introduced.
This rule detects functions that are never called from inside a translation unit, and cannot be called from the outside.
Noncompliant code example
static void unusedStaticFunction() { // Noncompliant
}
class Server {
public:
void start() { // Compliant, the member function "start()" is public
log("start");
}
private:
void clear() { // Noncompliant, the member function "clear()" is unused
}
void log(const char * msg) { // Compliant, the member function "log()" is used in "start() { ... }"
printf(msg);
}
};
Resources
- MISRA C++:2008, 0-1-10 - Every defined function shall be called at least once.