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);
  }
};
----

== See

* MISRA {cpp}:2008, 0-1-10 - Every defined function shall be called at least once.

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
