このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
MISRA C++:2008 Rule 5-0-8
An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression.
説明
ルール定義
An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression. 1
根拠
このチェッカーによってフラグが設定される式は、MISRA™ C++ ドキュメンテーションの cvalue 式の詳細仕様に従います。
式を評価し、後でその結果を別の型にキャストする場合、そのキャストは評価の潜在型 (式にあるオペランドのデータ型のうち範囲が最も広いもの) には影響しません。たとえば、この例では 2 つの short
型のオペランドの合計がより大きな int
型にキャストされます。
short op1; short op2; int res; res= static_cast<int> (op1 + op2);
int
を使用した合計であると見なされることがあります。レポート内の追加のメッセージ
An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression.
潜在型 typeBeforeConversion
の複合式は、符号属性が同じである、より小さな整数型にのみキャストできますが、変換先の型は typeAfterconversion
です。
トラブルシューティング
ルール違反が想定されるものの、Polyspace® から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
グループ: Expressions |
カテゴリ: 必要 |
バージョン履歴
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.