Why is this an issue?
The restrict
type qualifier is a guarantee by the programmer that there are no other pointers with access to the referenced object,
and that the object does not overlap with any other object in memory. Its use may allow the compiler to generate more efficient byte code.
However, this is a tricky language feature to use correctly, and there is significant risk of unexpected program behavior if restrict
is misused. Therefore, restrict
should not be used.
Noncompliant code example
void user_copy (
void * restrict p, // Noncompliant parameter
void * restrict q, // Noncompliant parameter
size_t n
) {
// ...
}
Resources
- MISRA C:2012, 8.14 - The restrict type qualifier shall not be used
- CERT, EXP43-C. - Avoid undefined behavior when using restrict-qualified pointers