MISRA Discussion Forums
Rule A13-2-3 - Relational operator shall return a boolean value - 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: Rule A13-2-3 - Relational operator shall return a boolean value (/showthread.php?tid=1593)



Rule A13-2-3 - Relational operator shall return a boolean value - DelayShot - 08-12-2021

Hi, 

the rule mentioned in the title states:

Rule A13-2-3 (required, implementation, automated) A relational operator shall return a boolean value.

The AUTOSAR document then proceeds to give some examples where the compliant ones have the function declaration stating the return type as `bool`.

So, to be compliant with the rule, is it necessary to just check the return type of the function? Or should we try to evaluate the type of the object returned in the return statement inside the function in order to see if it is an actual `bool` and that no implicit casts were used? 

By just looking at the examples, based also on where the `// Compliant` and `// Non-compliant` comments are, it seems to me that checking the function type signature in its prototype is enough.

What do you think?

Thanks.


RE: Rule A13-2-3 - Relational operator shall return a boolean value - misra cpp - 11-01-2022

You are right that this rule simply requires that the return type be 'bool'  (a typedef alias for bool would also be acceptable)

Any implicit conversions of non-Booleans values in a Boolean context should be caught by other rules.

(Sorry for the delay in replying, we had a log-in problem with the Bulletin Board)