Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-5272

Moved-from objects should not be relied upon

    XMLWordPrintable

    Details

    • 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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              massimo.paladin Massimo PALADIN
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: