Qt-Autosar-A12.8.4ΒΆ
Move constructor shall not initialize its class members and base classes using copy semantics
Required inputs: IR
std::move to explicitly transfer
resources.
Bad code (move constructor using copy semantics):
class Data {
std::string data_;
public:
Data(Data&& other) {
data_ = other.data_; // ERROR: copy ctor called instead of move ctor
}
};
Good code (move constructor using move semantics):
class Data {
std::string data_;
public:
Data(Data&& other) {
data_ = std::move(other.data_); // OK: transfer ownership
}
};
class Container {
std::vector<int> items_;
public:
Container(Container&& other) noexcept
: items_(std::move(other.items_)) {} // OK: move semantics for members
};
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
move_constructor |
Move constructor shall not initialize using copy semantics. |
None |
False |
Options
This rule shares the following common options: 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
This rule has no individual options.