AUTOSAR C++14 Rule M0-1-8
All functions with void return type shall have external side effect(s)
Since R2022a
Description
Rule Definition
All functions with void return type shall have external side effect(s).
Rationale
A function that has a void
return type does not return anything. When
such a function has no external side effects, it does not contribute to the output and
consumes time. That these functions have no contribution to the output of the program might
be contrary to developer expectation. Such a function might be unnecessary or indicate
issues in the program design. Avoid such functions.
The MISRA C++:2008 standard considers these effects as external side effects:
Reading or writing in resources such as a file or a stream.
Changing the value of a nonlocal variable.
Changing the value of a reference type argument.
Using a
volatile
object.Raising an exception.
Polyspace Implementation
Polyspace® flags the definition of a void
type function if the
function has no side effects.
Polyspace considers a function to have side effects if the function performs any of these tasks:
Calls an impure function other than itself.
Changes the value or dereferences a reference or pointer type argument.
Changes the value or deferences of a nonlocal variable.
Contains assembly instructions.
Accesses the
this
pointer of its parent class.Raises an exception. Raising exceptions is considered as a side effect even if the function does not exit with an exception.
Writes into an absolute address by using a local pointer.
Accesses a
volatile
object, class member, orstruct
member.Sets the value of a class or
struct
member.
This checker does not flag these entities:
Standard implementations of placement
new
anddelete
functions.Constructors and destructors.
Virtual class member functions that are empty.
Lambda objects.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Language independent issues |
Category: Required, Automated |
Version History
Introduced in R2022a