Menu

Access of moved variable FP

Martin
2022-09-20
2022-09-21
  • Martin

    Martin - 2022-09-20

    Hi,

    for the code

    class Foo
    {
          std::unique_ptr<Bar> m_Child;
    };
    void Foo::foobar()
    {
          barfoo(std::move(m_Child));
          m_Child.reset(new Bar());
    }
    

    cppcheck head outputs:

    ./cppcheck --enable=all --inconclusive  /home/user/Desktop/foo.cpp 
    Checking /home/user/Desktop/foo.cpp ...
    /home/user/Desktop/foo.cpp:8:7: warning: inconclusive: Access of moved variable 'm_Child'. [accessMoved]
          m_Child.reset(new Bar());
          ^
    /home/user/Desktop/foo.cpp:7:14: note: Calling std::move(m_Child)
          barfoo(std::move(m_Child));
                 ^
    /home/user/Desktop/foo.cpp:8:7: note: Access of moved variable 'm_Child'.
          m_Child.reset(new Bar());
          ^
    

    reset() should be allowed after move() though?

    Best regards,
    Martin

     

    Last edit: Martin 2022-09-20
  • CHR

    CHR - 2022-09-21

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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.