| Issue |
110223
|
| Summary |
Invalid iterator substitution in `modernize-use-ranges` fix-it
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
srpgilles
|
If I run clang-tidy v19.1.0 from Homebrew on macOS / XCode 16 over this small snippet:
```c++
#include <algorithm>
#include <iostream>
#include <vector>
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
{
std::vector<int> indexes { 1, 2, 7, 8, 4, 5 };
std::sort(indexes.begin(), indexes.end());
auto logical_end = std::unique(indexes.begin(), indexes.end());
if (logical_end != indexes.end())
std::cout << "There were duplicates\n";
return EXIT_SUCCESS;
}
```
I get the following code:
```c++
#include <algorithm>
#include <iostream>
#include <vector>
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
{
std::vector<int> indexes { 1, 2, 7, 8, 4, 5 };
std::ranges::sort(indexes);
auto logical_end = std::ranges::unique(indexes);
if (logical_end != indexes.end())
std::cout << "There were duplicates\n";
return EXIT_SUCCESS;
}
```
which is incorrect as `std::ranges::unique` returns a `std::ranges::in_out_result` (I got the same mistake with `std::ranges::copy`).
Replacing the generated:
```c++
auto logical_end = std::ranges::unique(indexes);
```
by:
```c++
auto [_, logical_end] = std::ranges::unique(indexes);
```
would fix it.
At any rate, thanks a lot for this extremely useful new diagnostic: I upgraded my whole codebase in less than 30 minutes 🙂
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs