メインコンテンツ

MISRA C:2023 Rule 16.2

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement

R2024a 以降

説明

ルール定義

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement 1

根拠

C 標準では、switch ラベル (たとえば、case または default) を switch ステートメント本体内の任意のステートメントの前に置くことを許可しています。この柔軟性が原因で、構造化されていないコードになることがあります。構造化されていないコードを回避するには、switch ラベルを必ず switch ステートメント本体の一番外側のレベルにのみ置くようにします。

トラブルシューティング

ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を参照します。

チェック情報

グループ: switch ステートメント
カテゴリ: 必要
AGC カテゴリ: 推奨

バージョン履歴

R2024a で導入


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.