switch statement has no case labels

ID

objectivec.correctness.empty_switch_statement

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Code

Language

Objective-C

Description

Reports a switch whose body holds nothing at all — no case, no default, no statement — whether the braces are written on one line or across several. A switch with any label, or one whose braces carry an explanatory comment, is not reported.

Rationale

A switch with no labels evaluates its controlling expression and discards the result: the statement is dead, and if that expression has a side effect the code now depends on a construct that looks like a no-op. It is what remains when the last case is deleted, and it is also the shape of a dispatch that was scaffolded and never filled in. Either way an enumeration is being switched on with no arm handling any of its values.

The following code illustrates the pattern detected by this rule:

@implementation Machine
- (void)dispatchOnOneLine:(XYState)state {
    // FLAGGED: switch statement has no case labels
    switch (state) { }
}

- (void)start {
    NSLog(@"starting");
}
@end

Remediation

Add the case labels the enumeration needs, with a default for the values you do not handle — or delete the switch outright if the dispatch is genuinely gone, keeping the controlling expression only if it has a side effect worth performing on its own.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved