Issue 84314
Summary [clang-tidy] `bugprone-unused-return-value` false negative for `unique_ptr` assignment
Labels clang-tidy
Assignees
Reporter zufuliu
    https://godbolt.org/z/a6f19rboW

```c++
// clang-tidy --checks=bugprone-unused-return-value test.cpp --
#include <cstdlib>
#include <memory>

extern std::unique_ptr<int> alloc();

struct Foo {
    std::unique_ptr<int> foo;
 std::unique_ptr<int> bar;
    void *baz;
    Foo() {
        foo = std::make_unique<int>();
        bar = alloc();
        baz = malloc(sizeof(int));
    }
};

void f1(std::unique_ptr<int> &foo) {
    foo = std::make_unique<int>();
}

void f2(std::unique_ptr<int> &bar) {
    bar = alloc();
}

void f3(void* &baz) {
    baz = malloc(sizeof(int));
}
```

```
--checks=bugprone-unused-return-value
[<source>:12:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]](_javascript_:;)
   12 |         foo = std::make_unique<int>();
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[<source>:13:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]](_javascript_:;)
   13 |         bar = alloc();
      |         ^~~~~~~~~~~~~
[<source>:19:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]](_javascript_:;)
   19 | foo = std::make_unique<int>();
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[<source>:23:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]](_javascript_:;)
   23 |     bar = alloc();
      |     ^~~~~~~~~~~~~
4 warnings gener
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to