19-11-2020, 09:24 PM
Unfortunately the function bodies are not switched.
The short-circuit evaluation is a required part of the language: C++ reference on logical operators
Code:
bool non_compliant_and (void)
{
bool const b1 = random_bool(); // Assume this value is false.
bool const b2 = random_bool(); // This can be any value.
/* Due to short-circuit evaluation, the value of b2 is never evaluated (read).
* This causes a DU dataflow anomaly for b2, and hence the MISRA C++ Rule 0-1-6 violation.
*/
return b1 && b2;
}
The short-circuit evaluation is a required part of the language: C++ reference on logical operators