Menu

Inconsistent accessMoved Warning

safans
2 days ago
2 days ago
  • safans

    safans - 2 days ago

    Hi, I found an inconsistent behavior in the accessMoved detector. Please see the two programs below.

    Cppcheck should report consistent accessMoved warnings for both programs because they are semantics-equivalent. However, it reports a warning for the first program but does not report this type of warning for the second one. Therefore, I believe this is inconsistent behavior.

    First Program

    #include <iostream>
    #include <string>
    #include <utility>
    
    void foo(std::string);
    int main()
    {
        std::string s = "test";
        foo(std::move(s));
        std::cout << s << std::endl;
    }
    

    Second Program

    #include <iostream>
    #include <string>
    #include <memory>
    #include <utility>
    
    void foo(std::string);
    
    int main() {
      auto s = std::make_unique<std::string>("test");
      foo(std::move(*s));
      std::cout << *s << std::endl;
    }
    
     
  • CHR

    CHR - 2 days ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14861

     

Log in to post a comment.

Auth0 Logo