[clang-tools-extra] [clang-tidy] `use-ranges`: preserve used `unique` results (PR #196035)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Sat May 9 23:57:59 PDT 2026
================
@@ -43,6 +43,18 @@ void Positives() {
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
// CHECK-FIXES: std::ranges::reverse(I);
+ auto LogicalEnd = std::unique(I.begin(), I.end());
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a ranges version of this algorithm
+ // CHECK-FIXES: auto LogicalEnd = std::ranges::unique(I).begin();
+
+ bool AlreadyUnique = std::unique(I.begin(), I.end()) == I.end();
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use a ranges version of this algorithm
+ // CHECK-FIXES: bool AlreadyUnique = std::ranges::unique(I).begin() == I.end();
+
+ std::unique(I.begin(), I.end());
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
+ // CHECK-FIXES: std::ranges::unique(I);
+
----------------
zeyi2 wrote:
Could we add another test?
```cpp
auto LogicalEndWithPred = std::unique(I.begin(), I.end(), [](int A, int B) { return A == B; });
```
And check it gives fix-its: `std::ranges::unique(I, [](int A, int B) { return A == B; }).begin();`
https://github.com/llvm/llvm-project/pull/196035
More information about the cfe-commits
mailing list