Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-2949

Rule S6236: Rvalue reference members should not be copied accidentally

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.27
    • Component/s: C++, Rules
    • Labels:

      Description

      When a member of rvalue reference type is accessed from the xvalue of the object type (i.e. std::move'd object), then the expression has an lvalue type. That means that object may be copied, instead being moved as expected. Example:

      std::pair<std::string&& s, int> p(/*..*/);
      auto s = std::move(p).first; // copy is made instead of move
      

      Consider reporting problems in template instantions.
      For the pair, this may be fixed by use of std::get.

      Related LWG issue: wg21.link/lwg3527

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tomasz.kaminski Tomasz Kamiński
              Reporter:
              tomasz.kaminski Tomasz Kamiński
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: