Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 9.3.1 - iteration statement followed by 'try'
#1
It is possible to add the 'try' statement directly after 'while', for example:

class Exception{};
void f(int i)
{
    while(i) try {             // Non-compliant
        //...
    } catch(Exception e){
    }
}


I think this is non-compliant with the Rule 9.3.1, because 'try' is not a compound statement. However, accordingly to the standard 'try' should be always followed by a compound statement if it is inside a function. This code seems to be clear, so maybe this case could be added as an exception in the future versions of MISRA C++ standard.
Reply
#2
You are right, your example is non-compliant with 9.3.1.

Whilst 'try' is always followed by a compound statement, there are now a number of compound statements after the 'while', the 'try' and an arbitrary number of 'catch'es. For simplicity, we prefer 'while' followed by a single compound statement.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)