Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1144 Unused "private" methods should be removed
  3. RSPEC-3615

C-Family: Unused functions and methods should be removed

    XMLWordPrintable

    Details

    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended

      Description

      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 C++:2008, 0-1-10 - Every defined function shall be called at least once.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            alban.auzeill Alban Auzeill
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: