<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/110223>110223</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Invalid iterator substitution in `modernize-use-ranges` fix-it
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          srpgilles
      </td>
    </tr>
</table>

<pre>
    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 ðŸ™‚
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk2PIjcQ_TXmUgJ1u4HuPvSBj0HhFCmzkfaG3HbR7azbJnYZhvz6yAwTmBUTbVZ7ilayCsmuevWq6hUgQtCdRWzYbMlm65GI1Dv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