MISRA C++:2023 Rule 7.0.5
Integral promotion and the usual arithmetic conversions shall not change the signedness or the type category of an operand
自 R2024b 起
描述
规则定义
Integral promotion and the usual arithmetic conversions shall not change the signedness or the type category of an operand. 1
理由
一些从有符号数据类型到无符号数据类型的转换(或类型分类更改)可能会导致实现定义的行为。您可能会看到转换导致的意外结果。
Polyspace 实现
检查项会对以下情况进行标记:
从有符号整数数据类型到无符号整数数据类型的隐式转换,或反向转换。
检查项假定
ptrdiff_t是一个有符号整数。类型分类的更改。
根据 MISRA™ C++:2023 规范,规则检查项将类型分为四个类别:
字符:
char、wchar_t、char16_t和char32_t整数:有符号和无符号整数类型以及无限定作用域的枚举类型,包括
signed char和unsigned char浮点:
float、double和long double其他:
bool、void和nullptr_t
故障排除
如果您预期会出现违规,而 Polyspace® 未报告该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:标准转换 |
| 类别:必需 |
版本历史记录
在 R2024b 中推出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.