AutosarC++17_10-A0.1.2¶
The value returned by a function having a non-void return type that is not an overloaded operator shall be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
A called function may provide essential information about its process status and result through return statement. Calling a function without using the return value should be a warning that incorrect assumptions about the process were made.
Overloaded operators are excluded, as they should behave in the same way as built-in operators.
Exceptions
The return value of a function call may be discarded by use of a static_cast<void> cast, so intentions of a programmer are explicitly stated.
Example
// $Id: A0-1-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <algorithm>
#include <cstdint>
#include <vector>
std::uint8_t Fn1() noexcept { return 0U; }
void Fn2() noexcept {
std::uint8_t x = Fn1(); // Compliant
Fn1(); // Non-compliant
static_cast<void>(Fn1()); // Compliant by exception
}
void Fn3() {
std::vector<std::int8_t> v{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5};
std::unique(v.begin(), v.end()); // Non-compliant
v.erase(std::unique(v.begin(), v.end()), v.end()); // Compliant
}
See Also
- MISRA C++ 2008 [6]: Rule 0-1-7 The value returned by a function having a non- void return type that is not an overloaded operator shall always be used.
- HIC++ v4.0 [8]: 17.5.1 Do not ignore the result of std::remove, std::remove_if or std::unique.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
discarded_return_with_entity |
Return value of function discarded. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allowed_functions¶
allowed_functions : set[bauhaus.analysis.config.FunctionName] = {'memcpy', 'memmove', 'memset', 'strcat', 'strcpy', 'strncat', 'strncpy'}
check_operators¶
check_operators : bool = False
report_references¶
report_references : bool = False