| Issue |
84326
|
| Summary |
add clang-tidy check to suggest usage of `const_iterator` if possible
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
firewave
|
It be helpful to have a check which suggests to use `const_iterator` and/or the appropriate functions which provide it - if possible.
```cpp
#include <map>
std::map<int, int> cb();
void f()
{
std::map<int, int> m = cb();
std::map<int, int>::iterator I1 = m.begin(); // suggest const_iterator and/or cbegin()
auto I2 = m.begin(); // suggest cbegin()
std::map<int, int>::iterator it1 = m.find(0); // suggest const_iterator
auto it2 = m.find(0); // requires std::as_const() - not in scope - separate check?
auto I3 = m.cbegin(); // no warning
auto it3 = std::as_const(m).find(0); // no warning
}
```
This might make the suggestions of `modernize-use-auto` less prone to remove constness as outlined in #84324. This might also enable `misc-const-correctness` to report more cases.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs