Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-5536

Functions that are not used in a project should be removed

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Message:
      Remove this unused function.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++, Objective-C
    • Irrelevant for Languages:
      ABAP, APEX, C#, Cobol, CSS, Flex, Go, HTML, Java, JavaScript, Kotlin, PHP, PL/I, PL/SQL, Python, RPG, Ruby, Rust, Scala, Solidity, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Level:
      Semantic Analysis
    • Analysis Scope:
      Main Sources

      Description

      Unless you are in a library codebase context, functions that are declared in your program but never executed are dead code that 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.

      Note: S1144 is a subset of this rule; hence, it should be deactivated when this rule is activated.

      Noncompliant Code Example

      void unusedStaticFunction() { // Noncompliant
      }
      
      void unusedGlobalFunction() { // Noncompliant: it is not called in the entire program
      }
      
      void undefinedGlobalFunction(); // Noncompliant
      
      class A {
      public:
        A(int i) : i(i){} // Compliant it is called in "main"
        void startUsed() { // Compliant, the member function "startUsed" is called in "main"
        }
        void startUnused() { // Noncompliant, the member function "startUnused" is not called in the program
        }
      private:
        A(): i(0) { // Compliant, private and deleted constructor are an exception
        }
        int i;
      };
      
      int main() // Compliant, "main" is an exception.
      {
        A a{2};
        a.startUsed();
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              abbas.sabra Abbas Sabra
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: