Details

    • Type: Code Smell Detection
    • Status: Closed
    • Resolution: Duplicate
    • Labels:
    • Message:
      Remove or refactor this dead statement.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Targeted languages:
      C++, Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • CERT:
      MSC56-J., MSC07-CPP.
    • MISRA C 2012:
      2.2
    • MISRA C++ 2008:
      0-1-9

      Description

      Any executed statement whose removal would not affect program output constitutes dead code (also know as redundant code). It is unclear to a reviewer if this is intentional or has occurred due to an error.

      Noncompliant Code Example

      int16_t has_dead_code ( int16_t para ) 
      { 
        int16_t local = 99;
        para = para + local;
        local = para; // Noncompliant, local is never used
        if ( 0 == local )
        {
          local++; // Noncompliant, unreachable
        }
        return para;
      }
      

      Compliant Solution

      int16_t has_dead_code ( int16_t para ) 
      { 
        int16_t local = 99;
        para = para + local;
        return para;
      }
      

      See

      • MISRA C++:2008, 0-1-9
      • MISRA C:2012, 2.2
      • CERT, MSC56-J. - Detect and remove superfluous code and values
      • CERT, MSC07-CPP. - Detect and remove dead code

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: