MISRA Discussion Forums
A13-5-4 opposite operator clarification - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: A13-5-4 opposite operator clarification (/showthread.php?tid=1683)



A13-5-4 opposite operator clarification - aromauld - 26-04-2024

We would like to get clarification on what "opposite operators" means.

The referenced JSF guideline says (such as == and !=) which implies there are others, but there are no examples present other than "!= and ==". 

Presumably this includes relational operators, but it doesn't discuss how. This rule would seemingly imply that <= should be implemented using >=. But would this mean that it is considered non-compliant to implement it with operator >?


Code:
inline bool operator<=(const X& lhs, const X& rhs) { return !(lhs > rhs); }

Are relational operators allowed to call any other relational operators? Are there any other pairings that are considered opposites for this rule?


RE: A13-5-4 opposite operator clarification - misra cpp - 17-05-2024

Answering your questions in order:
- Yes, your code is compliant - we're not quite sure how you came to the conclusion we were expecting <= to be implemented with >=
- Yes, as in your example the implementation of <= can use >
- The rule applies to three pairs: == & != <= & > >= & <

A possible compliant implementation would be to define == and < and use std::rel_ops