MISRAC++2008-5-0-18
In this section:
Synopsis
(Required) >, >=, <, <= shall not be applied to objects of pointer type, except where they point to the same array.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
Comparing pointers cause undefined behaviour if they do not point to the same object. This check is identical to MISRAC++2023-8.9.1.
Coding standards
- MISRA C++ 2023 8.9.1
(Required) The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array
Code examples
The following code example fails the check and will give a warning:
void example() {
int a1[10];
int a2[10];
int* p1 = a1;
if ( p1 < a2 ) {} // Non-compliant
}
The following code example passes the check and will not give a warning about this issue:
#include <functional>
void example() {
int a1[10];
int a2[10];
int* p1 = a1;
if ( std::greater_equal<>{}(a2, p1) ) {} // Compliant
}