Why example in Rule 5-0-13 is non-compliant - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.5 Expressions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=134) +---- Thread: Why example in Rule 5-0-13 is non-compliant (/showthread.php?tid=1629) |
Why example in Rule 5-0-13 is non-compliant - kafka - 27-07-2022 Could someone please explain why the "if ( u8 && (bool_1 <= bool_2 ) )" in Rule 5-0-13 is non-compliant. RE: Why example in Rule 5-0-13 is non-compliant - misra cpp - 05-08-2022 The example above the line you quote, "if (u8)", is non-compliant because u8 is not of type bool. The rationale is that it is unclear whether the programmer recognises that (u8) is equivalent to (u8 != 0) or whether some other condition has been omitted. The example you quote is there to illustrate that 'u8' doesn't become an acceptable Boolean value when incorporated into a more complex expression. It is arguable that the condition isn’t non-compliant with 5-0-13, as the type of the logical && expression is bool. However, It is non-compliant with 5-3-1 “Each operand of the ! operator, the logical && or logical || operators shall have the type bool”. The comment ought to say ‘compliant with this rule, but non-compliant with 5-3-1’. |