[clang-tidy] modernize-use-ranges does not dereference pointer to container
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
clang-tidy: 22.1.1
```cpp
#include
#include
void f(std::vector *v, int x) {
auto i = std::find(v->cbegin(), v->cend(), x);
}
```
```console
$ clang-tidy --checks=modernize-use-ranges --fix a.cpp
1 warning generated.
a.cpp:5:12: warning: use a ranges version of this algorithm [modernize-use-ranges]
5 | auto i = std::find(v->cbegin(), v->cend(), x);
| ^~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~
| std::ranges::find v
a.cpp:5:12: note: FIX-IT applied suggested code changes
a.cpp:5:22: note: FIX-IT applied suggested code changes
5 | auto i = std::find(v->cbegin(), v->cend(), x);
| ^
a.cpp:5:34: note: FIX-IT applied suggested code changes
5 | auto i = std::find(v->cbegin(), v->cend(), x);
| ^
clang-tidy applied 3 of 3 suggested fixes.
```
gives wrong code
```cpp
auto i = std::ranges::find(v, x);
```
which should be
```cpp
auto i = std::ranges::find(*v, x);
```
Contributor guide
Research direction
Start by reproducing the issue with the provided a.cpp example using clang-tidy and the modernize-use-ranges check. Inspect how the check handles iterator expressions from a pointer to a container; done means the fix produces std::ranges::find(*v, x) and does not change the intended container access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100