<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84314>84314</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] `bugprone-unused-return-value` false negative for `unique_ptr` assignment
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zufuliu
</td>
</tr>
</table>
<pre>
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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVs2S4jYQfprm0mXKlmywDxxgGF4hxy3ZahvtConohwQOefaUDCwMxZKp5JAal8oYq_vr_j6p5Rbeq8EQLaBaQbWeiBi21i1OsY9axUlr5XGxDWHvgS-BbYBtBitbq8PUugHY5gRsI2Z90bjW_gb5GvLl5T7Lz6MDtkrj_HaEwE4LM2RBySNmWbel7ocHvm7jsHfWUBZN9CQzRyE6kx2EjoSBfJh2-z1m2RWKK9PpKAmBv3U-SK1a4O_PZne0s-54mxzv9GcgZ9AHmbjxZTTq90jf9sEBf1MmAH9HobXtgNXAGuCre28fXOwCbqxFmF9mEPE1XG_tT5jXlq1wN0tEPFglEdiyFacP7zfWntP7mEW6-pQaX9_i7MQP-nYO9jPQA7erbyvc6PuM_83mNNrsrkZencj2wOoEzZpHH5ivLwLO1w9ijuz6ImG8EgXYLCn4SPbfEL0lc5cA-0QCaWEeE3il1tNAHFidnoAtz5inJ5ifV_cW41p0Tyvx_PeTBXfxrVbA37yNrqMkIl8WDPiyAb7EP4QzygzpMWwJz2V6hiCJ7RHDVnnso-mCsgb91kYt0diALaFU3tEgnCQJfIWGBk1dUGZAFXAnjqhJSAwWyTnrPEK1eplttU6D1d_FQfjOqX0YV3GVZLpqWjCE-Rv-9_pIKFC9__Xi-qV8_OvKxz_I989HxL31g1y_lCdJU31NeZqR8P-yqxj_srKx2676_I56upvKK3mPAxlyD6ffRC64bHgjJrQo5nlTFyXP68l2MaOS1UUtZCML0eZN3pb5nM-KigmeV7N6ohYsZ2XO83nBWJWX01YU86buZSXrOZdtDWVOO6H0VOvDLjVGE-V9pEVd8qKcaNGS9mODxdit8wHGUsPlFskpa-Pgocy18sHfYIIKemzN7tyqNcIsf6n7LMdeaE9pBUVQB8LeuuR1902b5Xju_XZkwiQ6_djmqbCN7bSzO2CblNDlJ9s7-526AGwzkvTANiPPvwMAAP__ugoakA">