llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

Static-Analyzer cplusplus.Move is unaware of std::lib types with well defined move semantics #62517

Open njames93 opened 1 year ago

njames93 commented 1 year ago

The static analyzer is currently unaware of types defined in the standard library with a valid and specified state after calling move, resulting in false positives.

In this example:

#include <vector>

template <typename T>
void eat(std::vector<T>);

bool cond();

void foo() {
    std::vector<int> a;
    while (cond()) {
        if (cond()) {
            eat(std::move(a));
        }
        a.push_back(2);
    }
}

According to the standard, A moved from vector is:

However the static-analyzer complains that after the call to eat, a is left in a valid but unspecified state, despeite the fact its known to be in a valid and empty state.

Ideally the analyzer should be aware of standard library types which are left in a valid and specified state after moves, and It should also be aware of their allocators when determining their state

https://godbolt.org/z/xrjeoeqhM

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-static-analyzer