AutosarC++18_03-A8.4.5¶
“consume” parameters declared as X && shall always be moved from
Required inputs: IR
| Level | required |
|---|---|
| Target | design |
| Enforcement | automated |
Rationale
A ”consume” parameter is declared with a type of rvalue reference to non-const non- template type (X &&). This documents that the value will be consumed in the function (i.e. left in a moved-from state) and requires an explicit ’std::move’ at the call site if an lvalue is passed to the function (an rvalue reference can implicitly bind only to an rvalue).
Note: Other operations may be performed on the ”consume” parameter before being moved.
Example
// $Id: A8-4-5.cpp 305588 2018-01-29 11:07:35Z michal.szczepankiewicz $
#include <string>
#include <vector>
class A {
public:
explicit A(std::vector<std::string> &&v)
: m_v{std::move(v)} // Compliant, move from consume parameter
{}
private:
std::vector<std::string> m_v;
};
class B {
public:
explicit B(std::vector<std::string> &&v)
: m_v{v} // Non-Compliant, consume parameter not moved from
{}
std::vector<std::string> m_v;
};
See Also
- C++ Core Guidelines [10]: F.18: For ”consume” parameters, pass by X&& and std::move the parameter
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_move_consume |
“consume” parameters shall always be moved from |
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
exclude_move_assignments_and_constructors¶
exclude_move_assignments_and_constructors : bool = True
moving_routines¶
moving_routines : set[bauhaus.analysis.config.QualifiedName] = set()
std::move.