MISRAC++2023-8.2.6
In this section:
Synopsis
(Required) An object with integral, enumerated, or pointer to void type shall not be cast to a pointer type
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Casting from integral types to pointer types can lead to unspecified behavior This check is identical to MISRAC++2008-5-2-8.
Coding standards
- MISRA C++ 2008 5-2-8
(Required) An object with integer type or pointer to void type shall not be converted to an object with pointer type.
Code examples
The following code example fails the check and will give a warning:
struct S { int i; };
void example(void * p1) {
S* s1 = static_cast< S* >( p1 ); // Non-compliant
}
The following code example passes the check and will not give a warning about this issue:
void example(void * p1) {
auto p = const_cast< void const* >( p1 ); // Compliant
}