MISRA C:2023 Rule 11.8
A conversion shall not remove any const,
volatile, or _Atomic qualification from the type
pointed to by a pointer
Since R2024a
Description
Rule Definition
A conversion shall not remove any const,
volatile, or _Atomic qualification from the type
pointed to by a pointer1
.
Rationale
This rule forbids conversions that violate type qualification:
Casts from a pointer to a
constobject to a pointer that does not point to aconstobject. Removing theconstqualifier allows the program to modify objects that are intended to be read-only. Attempting to access such a converted object can result in an exception.Casts from a pointer to a
volatileobject to a pointer that does not point to avolatileobject. Removing thevolatilequalifier can allow the compiler to remove accesses to this object during optimization.Casts from a pointer to an
_Atomicobject to a pointer that does not point to a_Atomicobject. Removing the_Atomicqualifier allows the program to circumvent the lock status of an object, resulting in memory corruption.
Polyspace Implementation
Polyspace® flags both implicit and explicit conversions that violate this rule.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Pointer Type Conversions |
| Category: Required |
| AGC Category: Required |
Version History
Introduced in R2024a
See Also
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.