AutosarC++18_03-A8.4.9¶
“in-out” parameters declared as T & shall be modified
Required inputs: IR
| Level | required |
|---|---|
| Target | design |
| Enforcement | automated |
Rationale
An ”in-out” parameter is declared with a type of reference to non-const. This means that a fully constructed object is passed into the function that can be read as well as modified.
Note: Completely replacing the passed in object without reading any data from it would make it an ”out” parameter instead and is not considered compliant with this rule, also see rule: A8-4-8
Example
// $Id: A8-4-9.cpp 306178 2018-02-01 15:52:25Z christof.meerwald $
#include <cstdint>
#include <numeric>
#include <string>
#include <vector>
// Non-Compliant: does not modify the "in-out" parameter
int32_t Sum(std::vector<int32_t> &v) {
return std::accumulate(v.begin(), v.end(), 0);
}
// Compliant: Modifying "in-out" parameter
void AppendNewline(std::string &s) { s += ’\n’; }
// Non-Compliant: Replacing parameter value
void GetFileExtension(std::string &ext) { ext = ".cpp"; }
See Also
- C++ Core Guidelines [10]: F.17: For ”in-out” parameters, pass by reference to non-const
- JSF December 2005 [7]: AV Rule 117.2: An object should be passed as T& if the function may change the value of the object.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
complete_replacement |
“in-out” completely replaced without being read. |
None |
False |
missing_modify |
“in-out” parameters not modified, consider making it const. |
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
allow_move_parameters¶
allow_move_parameters : bool = False
Note: move-constructors and move-assignments are allowed in either case.
exclude_constructors¶
exclude_constructors : bool = True
exclude_operators¶
exclude_operators : bool = False
Note: if set to true, this also sets exclude_shift_operators to true.
exclude_shift_operators¶
exclude_shift_operators : bool = False
operator<<(), operator<<=(),
operator>>(), and operator>>=()).
exclude_unnamed_parameters¶
exclude_unnamed_parameters : bool = False