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

S6023: Fix false-negative on 'optional' on class type with non-trivial-assigment

    XMLWordPrintable

    Details

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

      Description

      The issues is not raised if the optional contains an class type with non-trivial-assigment. Code example:

      void testStdNullopt(const std::optional<std::string> &arg) {
        std::string i = 0;
        if (arg != std::nullopt) { // CHECK :7 :26 S6023:Simplify this code by using "std::optional" member function "value_or".
          i = arg.value();
        } else {
          i = "asdads";
        }
        (void)i;
      }
      

        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: