Menu

accessMoved false positive

Andrei
2023-06-07
2023-06-07
  • Andrei

    Andrei - 2023-06-07

    Hi. Just updated to 2.10 and found following false positive:
    In the following code line
    foo(std::move(hhh)).then( { return !f; });
    would be reported as "CWE: 672 Access of moved variable 'hhh'."
    Version used: 2.10
    Version last ok (not sure): 2.8

    Interesting note:
    if change
    "foo(std::move(hhh)).then( { return !f; }); return 0;" to just "return foo(std::move(hhh)).then( { return !f; });" no errors reported.

    #include <functional>
    
    class Value {
    public:
        Value() = default;
        Value(const Value&) = default;
        Value(Value&&) = default;
    
        bool empty() {
            return true;
        }
    };
    
    class Caller
    {
    public:
        explicit Caller(Value ints): _ints(std::move(ints)) {
        }
        bool then(std::function<bool(bool)>&& f) {
            return f(true);
        }
    
        Value _ints;
    };
    
    Caller foo(Value ints)
    {
        return Caller(std::move(ints));
    }
    
    int main()
    {
        Value hhh;
        foo(std::move(hhh)).then([](bool f) { return !f; });
        return 0;
    }
    

    Best,
    Andrei.

     
  • CHR

    CHR - 2023-06-07

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

     

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.