-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Message:Delete this unreachable code or refactor the code to make it reachable.
-
Highlighting:
- primary: The first line of dead code.
- secondary: The statement[s] which exit the flow.
- message: "Statement exiting the current code block."
-
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
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
- MITRE, CWE-561 - Dead Code
- CERT, MSC56-J. - Detect and remove superfluous code and values
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- deprecates
-
RSPEC-1538 Unreachable code
- Closed
- is duplicated by
-
RSPEC-894 There should not be unreachable code
- Closed
-
RSPEC-901 Dead code should be removed
- Closed
- is implemented by
-
SONARPY-800 S1763: Add a message on the secondary location
-
- Closed
-
-
CPP-614 Rule: Jump statements should not be followed by other statements
-
- Closed
-
-
SONARSLANG-61 Rule: Jump statements should not be followed by dead code
-
- Closed
-
-
SONARSLANG-143 Enable in Ruby rule S1763 (CodeAfterJumpCheck)
-
- Closed
-
-
SONARSLANG-226 [Scala] Enable Rule: S1763 Jump statements should not be followed by dead code
-
- Closed
-
-
SONARSLANG-315 [Apex] Enable Rule: S1763 Jump statements should not be followed by dead code
-
- Closed
-
-
SONARSWIFT-65 Rule: Jump statements should not be followed by other statements
-
- Closed
-
-
SONARTSQL-29 Rule: Jump statements should not be followed by other statements
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
-
SONARSLANG-429 [Go] Enable rule S1763: RSPEC- Jump statements should not be followed by dead code
-
- Closed
-
-
SONARPLSQL-750 S1763: Add a message on the secondary location
-
- Closed
-
-
SONARTSQL-121 Update rule "Jump statements should not be followed by other statements" to be based on CFG
-
- Closed
-
-
SONARSLANG-447 [Go] - FP on S1763 when a semicolon is added
-
- Closed
-
-
SONARSLANG-448 [Go] - FP on S1763 when jumps are followed by labelled code
-
- Closed
-
- is related to
-
CPP-2771 S1763: Use double quotes for code in the message
-
- Open
-
-
CPP-2795 S1763: Improve the location for the unreachable code report, involving "operator[]"
-
- Open
-
-
CPP-2797 S1751, S1763: deduplicate, prefer specific S1751 over generic S1763
-
- Open
-
-
SONARSLANG-172 S1763 should consider more kinds of "jump" statements
-
- Open
-
-
SONARSLANG-88 Support statements list in match case in Slang
-
- Closed
-
- relates to
-
SONARPHP-1089 S1763: Add a message on the secondary location
-
- Closed
-
-
RSPEC-902 Unused functions and methods should be removed
- Closed
-
SONARSLANG-439 [Go] S1763 FP on function with label
-
- Closed
-
-
RSPEC-897 Unused type declarations should be removed
- Active
-
RSPEC-905 Non-empty statements should change control flow or have at least one side-effect
- Active
-
RSPEC-1029 Class templates, function templates, class template member functions and class template static members should be instantiated at least once
- Active
-
RSPEC-1116 Empty statements should be removed
- Active
-
RSPEC-1172 Unused function parameters should be removed
- Active
-
RSPEC-1751 Loops with at most one iteration should be refactored
- Active
-
RSPEC-1854 Unused assignments should be removed
- Active
-
RSPEC-1862 Related "if/else if" statements should not have the same condition
- Active
-
RSPEC-1879 Unused macros should be removed
- Active
-
RSPEC-5918 Tests should be skipped explicitly
- Active
-
RSPEC-1475 "STOP RUN" or "GOBACK" should be the last statement of a sequence
- Active
- links to
1.
|
PHP | RSPEC-2013 |
|
Active | Unassigned | |
2.
|
PL/SQL | RSPEC-2395 |
|
Active | Unassigned | |
3.
|
Swift | RSPEC-2478 |
|
Active | Unassigned | |
4.
|
JavaScript | RSPEC-2745 |
|
Active | Unassigned | |
5.
|
Python | RSPEC-2775 |
|
Active | Unassigned | |
6.
|
T-SQL | RSPEC-4106 |
|
Active | Unassigned | |
7.
|
Go | RSPEC-4565 |
|
Active | Unassigned | |
8.
|
Kotlin | RSPEC-4712 |
|
Active | Unassigned | |
9.
|
Ruby | RSPEC-4779 |
|
Active | Unassigned | |
10.
|
Scala | RSPEC-4942 |
|
Active | Unassigned | |
11.
|
Apex | RSPEC-5007 |
|
Active | Unassigned | |
12.
|
C-Family | RSPEC-5368 |
|
Active | Unassigned |