Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way, MISRA C++ 2008 recommended
-
Covered Languages:C++
-
Remediation Function:Constant/Issue
-
Constant Cost:10min
-
Analysis Level:Abstract Interpretation
-
CERT:EXP63-CPP.
Description
By specification, objects supporting move operations will be left in a valid but unspecified state after the move. Even if in a valid state, the fact of being in an unspecified state leads to undefined behavior, you should not rely on their value.
Noncompliant Code Example
void f() {
A a;
A a2 = std::move(a);
a.fun(); // Noncompliant, a is moved-from
}
Compliant Solution
void f() { A a; A a2 = std::move(a); a2.fun(); }
See
- CERT, EXP63-CPP. - Do not rely on the value of a moved-from object
Attachments
Issue Links
- is implemented by
-
CPP-2120 Rule S5272: Moved-from objects should not be relied upon
-
- Closed
-
- is related to
-
RSPEC-5415 "std::move" should only be used where moving can happen
- Active
-
RSPEC-5500 Functions having rvalue reference arguments should "std::move" those arguments
- Active