# S1219: Switch statements should not contain non-case labels
id: non-case-label-in-switch
name: Switch Statements Should Not Contain Non-Case Labels
severity: error
category: maintainability
defect_class: correctness
inline_tier: blocking
language: c

message: "non-case label inside switch statement — move label outside or restructure"

description: |
  Regular labels inside switch statements create confusing control flow
  and are error-prone. Only case/default labels should appear in a switch.

  ✅ FIX: Move the labeled block outside the switch or restructure logic

  ```c
  switch (x) {
      case 1: process(); break;
  }
  after_switch:
      cleanup();  // GOOD - outside switch
  ```

query: |
  (labeled_statement
    (statement_identifier) @LABEL) @STMT

metavars:
  - LABEL
  - STMT

post_filter: c_label_in_switch

tags:
  - maintainability
  - c
  - misra
  - confusing

examples:
  bad: |
    switch (x) {
        case 1: break;
        cleanup: break;  // BAD - non-case label
    }

  good: |
    switch (x) {
        case 1: break;
    }
    cleanup:  // GOOD - outside switch
        do_cleanup();

has_fix: false
