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

S6023: Fix false-negative when value is moved from optional

    XMLWordPrintable

    Details

    • Type: False Negative
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.15
    • Fix Version/s: 6.27
    • Component/s: C++
    • Labels:
      None

      Description

      The issues is not raised if the value is moved from the optional as follows:

        if (arg.has_value()) { 
          i = std::move(arg.value()); // same for operator*
        } else {
          i = -1;
        }
        (void)i;
      

      However, we raise issue (I think correctly) on:

        if (arg.has_value()) { 
          i = std::move(arg).value();  // same for operator*
        } else {
          i = -1;
        }
        (void)i;
      

      The second case if the positive side-product of CPP-3085.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: