Rule 4-5-1 prohibits 'b1 |= b2;' ? - 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.4 Standard conversions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=133) +---- Thread: Rule 4-5-1 prohibits 'b1 |= b2;' ? (/showthread.php?tid=1277) |
Rule 4-5-1 prohibits 'b1 |= b2;' ? - grunwald - 28-09-2016 Neither `|` nor `|=` is listed as allowed operator. Does this mean the following code a violation of Rule 4-5-1? Code: bool b1 = false; Re: Rule 4-5-1 prohibits 'b1 |= b2;' ? - dg1980 - 29-09-2016 grunwald Wrote:Neither `|` nor `|=` is listed as allowed operator.x |= y is just short for x = x | y and bitwise operators are forbidden by the rationale in this rule. Code: FlexeLint for C/C++ (Unix) Vers. 9.00L, Copyright Gimpel Software 1985-2014 Re: Rule 4-5-1 prohibits 'b1 |= b2;' ? - mishak - 29-09-2016 Remember that any non-zero value will be considered as 'true' within a logical context, which can lead to surprises: Code: a = 0x01u; // This is logically 'true' Re: Rule 4-5-1 prohibits 'b1 |= b2;' ? - misra cpp - 28-10-2016 Yes, b1 |= b2 is prohibited As pointed out by dg1980, |= is a bitwise operator and the rationale of the rule prohibits the use of bitwise operators |