llvm / llvm/llvm-project

[clang-tidy] some `modernize-use-auto` warnings unnecessarily limited to C++17

Open
#180,443 7 comments 0 reactions 0 assignees View on GitHub
clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```cpp
#include

void f()
{
std::multimap mm;
auto range = mm.equal_range(0);
for (std::multimap::const_iterator I = range.first; I != range.second; ++I) {}
for (auto I = range.first; I != range.second; ++I) {}
}
```

The first loop is only reported with C++17 although it compiles using `auto` with C++11 (the second loop is the code after applying the fix-it in C++17 mode).

```
:7:10: warning: use auto when declaring iterators [modernize-use-auto]
7 | for (std::multimap::const_iterator I = range.first; I != range.second; ++I) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| auto
```

C++11: https://godbolt.org/z/9TKozqhKb
C++17: https://godbolt.org/z/4541xecsE

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.