Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 0.0.1
#1
Hello,

I apologize for this basic question, but can somebody please walk me through the first first five lines of MISRA C++ 2023 Rule 0.0.1?

bool f0();

int32_t f1( int32_t c, int32_t &res )
{
  if ( false && f0() ) { }       // Compliant - statement is considered to be reachable
  ...

In particular, why is the empty block statement ("{ }") considered to be reachable? My thinking is:

The condition of the if statement is considered a constant expression in C++17, one that evaluates to false. Therefore, we follow the third bullet point:
  • The blocks linked by the edges from a condition of a selection-statement or an iteration-statement are all considered reachable, except when the condition is a constant expression, in which case only the blocks linked by edges selected by the condition are considered reachable.

So, this seems to me that we should consider the empty block statement to be unreachable.

Also, what is the purpose of the first two bullet points:
  • Both operands of a reachable logical AND (&&) or logical OR (||) operator are considered reachable
  • All three operands of a reachable conditional operator ( ? : ) are considered reachable

Rule 0.0.1 is concerned with statements, so I don't see how subexpressions matter unless these rules are meant to convey that an expression such as ( false && f0() ) is potentially throwing and/or not a constant expression (for the purposes of this rule).. But, I feel like I may be reading too much into this.

Thank you in advance.
Reply
#2
We agree with you, the condition *is* a constant expression and so the example is Non-Compliant.

We should change it to:
bool b = false;
if (b && f0()) ...

We'll incorporate this into the next release or any amendments
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)