MISRA C++:2008 Rule 16-1-2
All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related
説明
ルール定義
All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related. 1
根拠
条件付きでコードのブロックを含めたり除外したりするには、#if...#elif...#else...#endif などのプリプロセッサ命令を使用します。このような命令のさまざまな分岐が別々のソース ファイルに存在する場合、混乱を招くコードになる可能性があります。すべての分岐が 1 つのプロジェクトに含まれていないと、コードが予期せぬ方法で動作する可能性があります。混乱と予期せぬ動作を回避するには、条件付きプリプロセッサ命令のすべての分岐を同じソース ファイルで保持します。
Polyspace 実装
以下のいずれかの条件に該当する場合、Polyspace® はこのルールの違反を報告します。
#else、#elif、または#endif命令のそれぞれに対応する#if命令がソース ファイル内に見つからない。#if命令のそれぞれに対応する#endif命令がソース ファイル内に見つからない。
トラブルシューティング
ルール違反が想定されるものの、Polyspace から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
| グループ: Preprocessing Directives |
| カテゴリ: 必要 |
バージョン履歴
R2013b で導入
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.