Skip to main content

IAR Embedded Workbench for Arm 10.10.x

Detecting unhandled cases in switch statements

In this section:
Description

Checks for a missing case label in a switch statement that does not have a default label.

Why perform the check

The check is useful, for example, to detect when an enum type has been augmented with a new value that is not yet handled in a switch statement.

How to use it

Compiler option: ‑‑runtime_checking switch

In the IDE: Project>Options>Runtime Checking>Switch

The check can be applied to one or more modules.

The check can be avoided by adding a default label.

How it works

The compiler inserts an implicit default label to perform the check in each switch statement that does not have a default label.

Example

Follow the procedure described in Getting started using C-RUN runtime error checking, but use the Switch option.

This is an example of source code that will be identified during runtime:

CRUN_UnhandledCaseInSwitch_src_Qt_01.png

C-RUN will report Unhandled case in switch. This is an example of the message information that will be listed:

CRUN_UnhandledCaseInSwitch_msg_Qt_01.png