Skip to content

Commit 6d83f55

Browse files
Based on PR reviews, improve code quality by making sure const correctness and modifying code format
Co-authored-by: Piotr Zegar <[email protected]>
1 parent 78d0410 commit 6d83f55

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,13 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
216216
if (!Call)
217217
continue;
218218
if (Function->getName() == "find") {
219-
unsigned ValueArgIndex = 2;
219+
const unsigned ValueArgIndex = 2;
220220
if (Call->getNumArgs() <= ValueArgIndex)
221221
continue;
222222
const Expr *ValueExpr =
223223
Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
224-
if (isa<CXXNullPtrLiteralExpr>(ValueExpr)) {
224+
if (isa<CXXNullPtrLiteralExpr>(ValueExpr))
225225
return;
226-
}
227226
}
228227
auto Diag = createDiag(*Call);
229228
if (auto ReplaceName = Replacer->getReplaceName(*Function))

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ Changes in existing checks
109109
- Improved :doc:`misc-redundant-expression
110110
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
111111
examples and fixing some macro related false positives.
112+
113+
- Fixed a false positive in :doc:`modernize-use-ranges
114+
<clang-tidy/checks/modernize/use-ranges>`updat the logic to suppress warnings for `nullptr` in `std::find`.
112115

113116
Removed checks
114117
^^^^^^^^^^^^^^

clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
void Positives() {
1313
std::vector<int> I, J;
14+
std::vector<std::unique_ptr<int>> K;
1415

1516
// Expect to have no check messages
16-
std::find(I.begin(), I.end(), nullptr);
17+
std::find(K.begin(), K.end(), nullptr);
1718

18-
std::find(I.begin(), I.end(), std::unique_ptr<int>());
19+
std::find(K.begin(), K.end(), std::unique_ptr<int>());
1920
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
20-
// CHECK-FIXES: std::ranges::find(I, std::unique_ptr<int>());
21+
// CHECK-FIXES: std::ranges::find(K, std::unique_ptr<int>());
2122

2223
std::find(I.begin(), I.end(), 0);
2324
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
@@ -86,13 +87,14 @@ void Positives() {
8687

8788
void Reverse(){
8889
std::vector<int> I, J;
90+
std::vector<std::unique_ptr<int>> K;
8991

9092
// Expect to have no check messages
91-
std::find(I.rbegin(), I.rend(), nullptr);
93+
std::find(K.rbegin(), K.rend(), nullptr);
9294

93-
std::find(I.rbegin(), I.rend(), std::unique_ptr<int>());
95+
std::find(K.rbegin(), K.rend(), std::unique_ptr<int>());
9496
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
95-
// CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), std::unique_ptr<int>());
97+
// CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), std::unique_ptr<int>());
9698

9799
std::find(I.rbegin(), I.rend(), 0);
98100
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
@@ -130,4 +132,3 @@ void Negatives() {
130132
// Pathological, but probably shouldn't diagnose this
131133
std::rotate(I.begin(), I.end(), I.end() + 0);
132134
}
133-

0 commit comments

Comments
 (0)