MISRAC++2008-5-2-4 (C++ only)
In this section:
Synopsis
(Required) C-style casts (other than void casts) and functional notation casts (other than explicit constructor calls) shall not be used.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Old style casts (other than void casts) were found. This check is identical to CAST-old-style, MISRAC++2023-8.2.2.
Coding standards
- CERT EXP05-CPP
Do not use C-style casts
- MISRA C++ 2023 8.2.2
(Required) C-style casts and functional notation casts shall not be used
Code examples
The following code example fails the check and will give a warning:
int example(float b)
{
return (int)b;
}
The following code example passes the check and will not give a warning about this issue:
int example(float b)
{
return static_cast<int>(b);
}