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

S5995: Issue is not raised for dependent type variable captured by copy for C++11

    XMLWordPrintable

    Details

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

      Description

      In C++11 mode the following code will raise issue for the bind capturing s, but will not raise it for dependen-type t.

      constexpr int multiply(int a, int b) { return a * b; }
      
      template <typename T>
      void testOnFunction(std::string& s, T& t) {
        (void)std::bind(multiply, std::placeholders::_1, s); // CHECK[cpp11+] :9 :54 S5995:Replace this use of "bind" with a lambda.
        (void)std::bind(multiply, std::placeholders::_1, t); // CHECK[cpp14+] :9 :54 S5995:Replace this use of "bind" with a lambda.
        // BUG: CPP-3179 - Not raised for C++11
      }
      

      The second (t capture) case does not fail under any C++11 limitations:

      • multiply is normal function, so generic lambda is not required
      • t is captured by copy, i.e. is not not-movable
      • This cannot be replaced by bind_front

      This is reduced example comming from file test/checks/BindFunctionCheck.cpp.

        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: