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 referenced from inside a translation unit, and cannot be referenced from the outside.
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);
}
};