Issue 87359
Summary [clang-tidy] `hicpp-ignored-remove-result` matches `std::unique*::release()`-like calls even though it is only supposed to match 3 specific functions
Labels bug, clang-tidy, new issue, false-positive
Assignees
Reporter whisperity
    [`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).
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to