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

There should not be unused parameters (named or unnamed) in the set of parameters for a virtual function and all the functions that override it

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove the unused parameter 'xxx'.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Targeted languages:
      C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • MISRA C++ 2008:
      0-1-12

      Description

      Unused function parameters are often due to design changes and can lead to mismatched parameter lists.

      Noncompliant Code Example

      class A
      {
      public:
        virtual void f ( uint16_t * para1, int16_t unusedpara ) = 0; // Noncompliant, unusedpara not used in any of the overriding functions.
      };
      
      class B1: public A
      {
      public:
        virtual void f ( uint16_t * para1, int16_t unusedpara ) // Noncompliant, unusedpara not used in any of the overriding functions.
        {
          *para1 = 1U;
        }
      };
      

      Compliant Solution

      class A
      {
      public:
        virtual void f ( uint16_t * para1 ) = 0; // Compliant, all parameters used at least once in an overriding function.
      };
      
      class B1: public A
      {
      public:
        virtual void f ( uint16_t * para1 ) // Compliant, all parameters used at least once in an overriding function.
        {
          *para1 = 1U;
        }
      };
      

      See

      • MISRA C++:2008, 0-1-12 - There shall be no unused parameters (named or unnamed) in the set of parameters for a virtual function and all the functions that override it.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              Anonymous Anonymous
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: