Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Should we check for a return statement for void function? Is this critical and affects the quality?

Options
ptalwar
ptalwar Posts: 3

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:

Comments

  • rozenau
    rozenau Posts: 15
    Options

    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.

Tagged