Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-8.9.1

In this section:
Synopsis

(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

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

Comparing pointers cause undefined behaviour if they do not point to the same object. Since C++14 one can use std::less etc for implementation defined behaviour. This check is identical to MISRAC++2008-5-0-18.

Coding standards
MISRA C++ 2008 5-0-18

(Required) >, >=, <, <= shall not be applied to objects of pointer type, except where they point to 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
}