Issue 90174
Summary [clang-tidy] bugprone-use-after-move - false-negative
Labels clang-tidy, false-negative
Assignees
Reporter PiotrZSL
    Example:

```
#include <memory>

struct A {};

struct ClassA
{
 ClassA(std::unique_ptr<A>);
};

class ClassB
{
 ClassB(std::unique_ptr<A> aaa)
        : aa(std::move(aaa))
    {
 a = std::make_unique<ClassA>(std::move(aaa));
    }
 std::unique_ptr<A> aa;
    std::unique_ptr<ClassA> a;
};

```
No issue from bugprone-use-after-move or from clang-analyzer-cplusplus.Move.

```
Example 2:
#include <iostream>
#include <memory>

struct Verbose
{
    Verbose() { std::clog << __PRETTY_FUNCTION__ << '\n'; }
    ~Verbose() { std::clog << __PRETTY_FUNCTION__ << '\n'; }
    Verbose(const Verbose&) { std::clog << __PRETTY_FUNCTION__ << '\n'; }
    Verbose(Verbose&&) { std::clog << __PRETTY_FUNCTION__ << '\n'; }
    Verbose& operator=(const Verbose&) { std::clog << __PRETTY_FUNCTION__ << '\n'; return *this; }
    Verbose& operator=(Verbose&&) { std::clog << __PRETTY_FUNCTION__ << '\n'; return *this; }

};

struct Test
{
    Test(std::unique_ptr<int> arg)
      : a(std::move(arg))
    {
 consume_again(std::move(arg));
    }
    void consume_again(std::unique_ptr<int>) {}
    std::unique_ptr<int> a;
};

int main() {
    std::unique_ptr<int> a = std::make_unique<int>(1);
    Test t1(std::move(a));
    Test t2(std::move(a));
}
```

Detected by clang-analyzer-cplusplus.Move, but not by bugprone-use-after-move
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to