<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87359>87359</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] `hicpp-ignored-remove-result` matches `std::unique*::release()`-like calls even though it is only supposed to match 3 specific functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
clang-tidy,
new issue,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
whisperity
</td>
</tr>
</table>
<pre>
[`hicpp-ignored-remove-result`](https://clang.llvm.org/extra/clang-tidy/checks/hicpp/ignored-remove-result.html) is a subclass of [`bugprone-unused-return-value`](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unused-return-value.html), initialised by passing three very specific functions (as documented) to the matcher regex of the parent check:
https://github.com/llvm/llvm-project/blob/31880df9947d58c160b691160c4714277be7c31e/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.cpp#L15-L20
However, it looks like the filters do not work. At first, I found a report on `std::unique_ptr<T>::release()`, which (according to the docs), should've only came from `bugprone-unused-return-value`, and **not** from `hicpp-ignored-remove-result`.
The problem goes deeper, however. It looks like when using `hicpp-ignored-remove-result`, it accepts a `release()` function for everything that begins with `std::unique`, whereas it shouldn't care about `release()` functions at all.
The issue appeared from a build of the upstream project on March 28, 14:00-ish UTC. (Last touch of the involved checkers is March 4.) Unfortunately, log rotation in our CI already ate the exact commit hash.
Ping @PiotrZSL, @bjosv, and @felix642, you were poking around this check.
----
## Reproducer
http://godbolt.org/z/brMKGc51n
### Code
```cpp
#include <algorithm>
#include <memory>
#include <mutex>
#include <vector>
void test0()
{
std::vector<int> V;
std::remove(V.begin(), V.end(), 42);
}
static std::mutex Mu;
extern void foo();
extern bool condition();
void test1()
{
std::unique_lock<std::mutex> Lock(Mu);
foo();
Lock.release();
}
struct HTTPWorkItem {};
void test2()
{
std::unique_ptr<HTTPWorkItem> Item(new HTTPWorkItem());
if (condition())
Item.release();
}
struct Disposable {
void* release();
};
struct UniqueDisposable {
void* release();
};
void test3()
{
Disposable D;
D.release();
UniqueDisposable UD;
UD.release();
}
namespace std {
struct unique_disposable {
void* release();
};
struct uniquely_disposable {
void* release();
};
}
void test4() {
std::unique_disposable StdUD;
StdUD.release();
std::uniquely_disposable StdUD2;
StdUD2.release();
}
```
### Outputs
#### `bugprone-unused-return-value`
```
<source>:9:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]
9 | std::remove(V.begin(), V.end(), 42);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:30:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]
30 | Item.release();
| ^~~~~~~~~~~~~~
3 warnings generated.
Suppressed 1 warnings (1 with check filters).
```
#### `hicpp-ignored-remove-result`
Except the **first** one, none other should appear!
```
<source>:9:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [hicpp-ignored-remove-result]
9 | std::remove(V.begin(), V.end(), 42);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:21:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [hicpp-ignored-remove-result]
21 | Lock.release();
| ^~~~~~~~~~~~~~
<source>:30:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [hicpp-ignored-remove-result]
30 | Item.release();
| ^~~~~~~~~~~~~~
<source>:62:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [hicpp-ignored-remove-result]
62 | StdUD.release();
| ^~~~~~~~~~~~~~~
<source>:65:5: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [hicpp-ignored-remove-result]
65 | StdUD2.release();
| ^~~~~~~~~~~~~~~~
6 warnings generated.
Suppressed 1 warnings (1 with check filters).
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWFtv47oR_jX0y8CGREm-POQha296Ft1FF7ubLdCXgiLHF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