Rule Definition
This expression gives the value that the function returns. The absence of a return with an expression leads to undefined behaviour (and the compiler may not give an error).
Remediation
Ensure to return an appropriate expression at all exit points
Violation Code Sample
Example
int32_t fn1 ( void )
{
} // Non-compliant
Fixed Code Sample
int32_t fn3 ( int32_t x )
{
if ( x > 100 )
{
throw 42; // Compliant by exception
}
return ( x ); // Compliant
}
Reference
Standards Reference:
MISRA C++ 2008, Rule 8-4-3: All exit paths from a function with non-void return type shall have an explicit return statement with an expression.
Related Technologies
Technical Criterion
CWE-394 - Unexpected Status Code or Return Value
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.