Menu

False positive passedByValue for std::unique_ptr.

Tim Finer
2016-09-26
2018-05-11
  • Tim Finer

    Tim Finer - 2016-09-26

    Functions with what looks like pass by value unique_ptr parameters aren't really. The functions are expressing ownership of the pointer and callers must use std::move at the call.

     
  • Jakub Kotur

    Jakub Kotur - 2018-05-08

    For me, the problem is only in the std::move is used in the initialization list. In the following example, cppcheck is reporting an issue only in line 6 (constructor) while it's not reporting an issue for line 8 (function). I'm using cppcheck 1.82.

    struct A {
       std::vector<int> x;
    };
    
    struct B {
        explicit B(A a) : a(std::move(a)) {}
    
        void Init(A _a) { a = std::move(_a); }
    
        A a;
    };
    
     
  • Daniel Marjamäki

    Thanks! I created the ticket https://trac.cppcheck.net/ticket/8570

     

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.