Rule 0.0.1 - 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++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.0 Language independent issues (https://forum.misra.org.uk/forumdisplay.php?fid=189) +---- Thread: Rule 0.0.1 (/showthread.php?tid=1686) |
Rule 0.0.1 - gdavis - 24-05-2024 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. RE: Rule 0.0.1 - misra cpp - 07-06-2024 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 |