02-12-2020, 09:36 PM
This clarification of the rule seems to be contrary to the first example provided in spec.
Is this also compliant because there is a path through the code where k is read?
Code:
int16_t critical (int16_t i, int16_t j)
{
int16_t result = 0;
int16_t k = ( 3 * i ) + ( j * j );
// should k be checked here?
if ( f2() )
{
// k will only be tested here if f2 returns true
// Initialization of k could be moved here
if ( k > 0 )
{
throw(42);
}
}
// Non-compliant- value of k not used if f2 () returns false
return result;
}