MISRA C++:2008 Rule 0-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).1
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
volatileobject.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.
Uses a
volatileobject.Contains assembly instructions.
Accesses the
thispointer 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.
Dereferences a local pointer that is assigned an absolute address.
Accesses a
volatileobject, class member, orstructmember.Sets the value of a class or
structmember.
This checker does not flag these entities:
Standard implementations of placement
newanddeletefunctions.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 |
Version History
Introduced in R2022a
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.