AUTOSAR C++14 Rule A5-2-2
Traditional C-style casts shall not be used
Description
Rule Definition
Traditional C-style casts shall not be used.
Rationale
C-style casts are difficult to distinguish in source code. Such casts cannot communicate the goal and necessity of the conversion. Code containing C-style casts is difficult to understand and debug.
Avoid C-style casts. C++ introduces explicit casting operations that are easily identified and clearly communicate the goal and necessity of each cast. Use these casting operations instead.
Polyspace Implementation
Polyspace® flags C-style casts and functional notation casts in your code. Compliant C++ style casting operations include:
std::static_cast
std::reinterpret_cast
std::const_cast
std::dynamic_cast
{}
notation casts
The reference_cast
operation from the Boost library and
the safe_cast
operation from the Microsoft® library are also allowed.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required, Automated |