llvm / llvm/llvm-project

[clang-tidy] readability-qualified-auto suggests to add a * that breaks compilation in other compilers

Open
#175,731 6 comments 0 reactions 0 assignees View on GitHub
clang-tidy false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

With the following code

```cpp
#include
#include

int main(int argc, char *argv[])
{
std::array myArray = {};

auto it = std::ranges::find(myArray, 3);

if (it != myArray.end()) {
printf("FOUND!");
}
}

```

It says

```
main.cpp:9:5: warning: 'auto it' can be declared as 'auto *it' [readability-qualified-auto]
9 | auto it = std::ranges::find(myArray, 3);
| ^~~~
| auto *

```

But if you add the * and try to compile it with MSVC it fails https://godbolt.org/z/csoe57Kea

Reading https://en.cppreference.com/w/cpp/algorithm/ranges/find.html I woud not expect the **it** variable to have a *

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the readability-qualified-auto warning with the C++ example in the issue and compare the suggested declaration against the MSVC result in the linked Godbolt case. Trace the check's handling of std::ranges::find and determine why it proposes a pointer; done means the diagnostic no longer recommends code that fails to compile with the reported compiler, with a regression test covering the case.

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
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.