MISRAC2012-Rule-17.4
Synopsis
(Mandatory) All exit paths from a function with non-void return type shall have an explicit return statement with an expression
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
For some execution paths, no return statement is executed in a function with a non-void return type. This check is identical to SPC-return, MISRAC2004-16.8, MISRAC++2008-8-4-3, MISRAC++2023-9.6.5.
Coding standards
- CERT MSC37-C
Ensure that control never reaches the end of a non-void function
- MISRA C:2004 16.8
(Required) All exit paths from a function with non-void return type shall have an explicit return statement with an expression.
- MISRA C++ 2008 8-4-3
(Required) All exit paths from a function with non-void return type shall have an explicit return statement with an expression.
- MISRA C++ 2023 9.6.5
(Required) A function with non-void return type shall return a value on all paths
Code examples
The following code example fails the check and will give a warning:
#include <stdio.h>
int example(void) {
int x;
scanf("%d",&x);
if (x > 10) {
return 10;
}
}
The following code example passes the check and will not give a warning about this issue:
#include <stdio.h>
int example(void) {
int x;
scanf("%d",&x);
if (x > 10) {
return 10;
}
return 0;
}