Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Refactor this piece of code to not have any dead code after this "[return|break|continue|goto|throw|switch]".
    • Highlighting:
      • primary: the jump statement, or the switch statement
      • secondary: the unreachable code after the jump
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      UnreachableCode, DeadCodeCheck
    • Targeted languages:
      ABAP, Cobol, Flex, PL/I, RPG, Rust, VB.Net, VB6
    • Covered Languages:
      C, C++, Go, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, Python, Ruby, Scala, Swift, T-SQL
    • Irrelevant for Languages:
      C#, Java, TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • CERT:
      MSC12-C., MSC56-J.
    • CWE:
      CWE-561
    • CPPCheck:
      duplicateBreak,unreachableCode
    • ESLint:
      no-unreachable
    • PVS-Studio:
      V612

      Description

      Some statements (return, break, continue, goto, switch) and throw expressions move control flow out of the current code block. So any unlabeled statements that come after such a jump are unreachable, and either this dead code should be removed, or the logic should be corrected.

      Noncompliant Code Example

      int fun(int a) {
        int i = 10;
        return i + a;       // Noncompliant 
        i++;             // dead code
      }
      

      Compliant Solution

      int fun(int a) {
        int i = 10;
        return i + a;
      }
      

      See

        Attachments

          Issue Links

          1.
          PHP RSPEC-2013 Language-Specification Active Unassigned
          2.
          PL/SQL RSPEC-2395 Language-Specification Active Unassigned
          3.
          Swift RSPEC-2478 Language-Specification Active Unassigned
          4.
          JavaScript RSPEC-2745 Language-Specification Active Unassigned
          5.
          Python RSPEC-2775 Language-Specification Active Unassigned
          6.
          T-SQL RSPEC-4106 Language-Specification Active Unassigned
          7.
          Go RSPEC-4565 Language-Specification Active Unassigned
          8.
          Kotlin RSPEC-4712 Language-Specification Active Unassigned
          9.
          Ruby RSPEC-4779 Language-Specification Active Unassigned
          10.
          Scala RSPEC-4942 Language-Specification Active Unassigned
          11.
          Apex RSPEC-5007 Language-Specification Active Unassigned
          12.
          C-Family RSPEC-5368 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: