Should we check for a return statement for void function? Is this critical and affects the quality?
Options
Similar to AUTOSAR rule A8_4_2-a (All exit paths from a function with non-void return type shall have an explicit return statement with an expression), should we also check for a return statement for void function? Is this critical and affects the quality?
Tagged:
0
Comments
-
I don't think so. The key point here is that flowing off the end of a value-returning function is undefined behavior. That's why it's forbidden by many coding guidelines. See e.g. MISRA C:2012 Rule 17.4, AUTOSAR C++ Rule A8-4-2, CERT MSC37-C or CERT MSC52-CPP.
Flowing off the end of the void function is well-defined as is equivalent to returning with no value, therefore it does not introduce any risk.2
