24-05-2024, 05:20 AM
(This post was last modified: 05-06-2024, 11:58 PM by gdavis.
Edit Reason: Disable inadvertent emoji in conditional operator
)
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:
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:
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.
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.