MISRA C++:2023 Rule 0.1.2
Description
Rule Definition
The value returned by a function shall be used 1 .
Rationale
The unused return value might indicate a coding error or oversight.
Overloaded operators are excluded from this rule because their usage must emulate built-in operators which might not use their return value.
If you want to deliberately ignore the return value of a function, cast the return value to void.
Polyspace Implementation
The checker reports a violation if:
The value returned by a function with non-
voidreturn type remains unused and not explicitly cast to avoidtype.A lambda,
std::functionobject, or a user-definedoperator()is invoked using the function call syntax, and its return value remains unused.
The checker does not report violations for the functions memcpy,
memset, memmove, strcpy,
strncpy, strcat, strncat because
these functions simply return a pointer to their first arguments.
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 R2024b
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.