[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
HerrCai0907 wrote:
Maybe it is more straightforward to detect function which return ref of member
variable like `const std::vector& get() const { return v; }` and bypass
the SideEffect check.
https://github.com/llvm/llvm-project/pull/127377
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/HerrCai0907 requested changes to this pull request. https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
@@ -51,7 +51,13 @@ static std::string
getFullPrefix(ArrayRef Signature) {
namespace {
AST_MATCHER(Expr, hasSideEffects) {
- return Node.HasSideEffects(Finder->getASTContext());
+ bool CheckArg = true;
+ if (const CXXMemberCallExpr *Call = dyn_cast(&Node)) {
+if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+ CheckArg = false;
+}
+ }
HerrCai0907 wrote:
According to comment in `HasSideEffects`.
> IncludePossibleEffects is false, this call treats certain expressions with
> potential side effects (such as function call-like expressions,
> instantiation-dependent expressions, or invocations from a macro) as not
> having side effects.
I think there are no relationship between `Call->isLValue() &&
Call->getMethodDecl()->isConst()` and `IncludePossibleEffects`.
https://github.com/llvm/llvm-project/pull/127377
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/Andrewyuan34 updated
https://github.com/llvm/llvm-project/pull/127377
>From fb2a4067517c1378ea6801ccd4a90207f607715f Mon Sep 17 00:00:00 2001
From: Andrewyuan34
Date: Thu, 20 Mar 2025 22:59:06 -0400
Subject: [PATCH] [clang-tidy] Fix false negative modernize-use-ranges when
using getter function
---
.../clang-tidy/utils/UseRangesCheck.cpp | 8 -
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++
.../checkers/modernize/use-ranges.cpp | 32 +--
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index f7a19cd72d500..052b149eb1d47 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -51,7 +51,13 @@ static std::string
getFullPrefix(ArrayRef Signature) {
namespace {
AST_MATCHER(Expr, hasSideEffects) {
- return Node.HasSideEffects(Finder->getASTContext());
+ bool CheckArg = true;
+ if (const CXXMemberCallExpr *Call = dyn_cast(&Node)) {
+if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+ CheckArg = false;
+}
+ }
+ return Node.HasSideEffects(Finder->getASTContext(), CheckArg);
}
} // namespace
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst
b/clang-tools-extra/docs/ReleaseNotes.rst
index 72aa05eb4dcd1..69410d1f36d44 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,11 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`modernize-use-ranges
+ ` check by correctly recognizes
+ const member functions returning lvalues as side-effect-free, preventing
+ missed transformations.
+
Removed checks
^^
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index 5aa026038b1cd..0927b617049e4 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -9,7 +9,15 @@
#include "use-ranges/fake_std.h"
#include "smart-ptr/unique_ptr.h"
-void Positives() {
+struct S {
+ std::vector v;
+
+ const std::vector& get() const { return v; }
+ std::vector& getMutable() { return v; }
+ std::vector getVal() const { return v; }
+};
+
+void Positives(S& s) {
std::vector I, J;
std::vector> K;
@@ -83,9 +91,19 @@ void Positives() {
my_std::find(I.begin(), I.end(), 6);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::find(I, 6);
+
+ std::find(s.get().begin(), s.get().end(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(s.get(), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().begin(), s.getMutable().end(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().begin(), s.getVal().end(), 0);
}
-void Reverse(){
+void Reverse(S& s){
std::vector I, J;
std::vector> K;
@@ -107,6 +125,16 @@ void Reverse(){
std::equal(I.begin(), I.end(), std::crbegin(J), std::crend(J));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::equal(I, std::ranges::reverse_view(J));
+
+ std::find(s.get().rbegin(), s.get().rend(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(s.get()), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().rbegin(), s.getMutable().rend(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().rbegin(), s.getVal().rend(), 0);
}
void Negatives() {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/Andrewyuan34 updated
https://github.com/llvm/llvm-project/pull/127377
>From 42077207cc104bfb33bf4768868cb7cdf5aecb7a Mon Sep 17 00:00:00 2001
From: Andrewyuan34
Date: Sun, 16 Feb 2025 01:36:14 -0500
Subject: [PATCH] [clang-tidy] Fix false negative modernize-use-ranges when
using getter function
---
.../clang-tidy/utils/UseRangesCheck.cpp | 8 -
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++
.../checkers/modernize/use-ranges.cpp | 32 +--
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f5fd0a47fb136 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -51,7 +51,13 @@ static std::string
getFullPrefix(ArrayRef Signature) {
namespace {
AST_MATCHER(Expr, hasSideEffects) {
- return Node.HasSideEffects(Finder->getASTContext());
+ bool CheckArg = true;
+ if (const CXXMemberCallExpr *Call = dyn_cast(&Node)) {
+if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+ CheckArg = false;
+}
+ }
+ return Node.HasSideEffects(Finder->getASTContext(), CheckArg);
}
} // namespace
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..f97c46d3b5dff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@ Changes in existing checks
` check by providing additional
examples and fixing some macro related false positives.
+- Improved :doc:`modernize-use-ranges
+ ` check by correctly recognizes
+ const member functions returning lvalues as side-effect-free, preventing
+ missed transformations.
+
Removed checks
^^
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..63a6946728f6f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -7,7 +7,15 @@
#include "fake_std.h"
-void Positives() {
+struct S {
+ std::vector v;
+
+ const std::vector& get() const { return v; }
+ std::vector& getMutable() { return v; }
+ std::vector getVal() const { return v; }
+};
+
+void Positives(S& s) {
std::vector I, J;
std::find(I.begin(), I.end(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -72,9 +80,19 @@ void Positives() {
my_std::find(I.begin(), I.end(), 6);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::find(I, 6);
+
+ std::find(s.get().begin(), s.get().end(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(s.get(), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().begin(), s.getMutable().end(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().begin(), s.getVal().end(), 0);
}
-void Reverse(){
+void Reverse(S& s){
std::vector I, J;
std::find(I.rbegin(), I.rend(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -87,6 +105,16 @@ void Reverse(){
std::equal(I.begin(), I.end(), std::crbegin(J), std::crend(J));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::equal(I, std::ranges::reverse_view(J));
+
+ std::find(s.get().rbegin(), s.get().rend(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(s.get()), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().rbegin(), s.getMutable().rend(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().rbegin(), s.getVal().rend(), 0);
}
void Negatives() {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/PiotrZSL approved this pull request. LGTM. PS: won't same issue exist in free standing functions ? Personally for me all 3 cases should be convertible to ranges. And probably should be some check for last one to point out dangling iterator. But that could be in scope for other change. https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
Andrewyuan34 wrote: ping... https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
Andrewyuan34 wrote: ping https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/Andrewyuan34 edited https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
llvmbot wrote:
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
Author: None (Andrewyuan34)
Changes
This PR fixes issue #124906, where `modernize-use-ranges` failed to
detect cases where a `const` member function returning an lvalue was
incorrectly assumed to have side effects, preventing the transformation.
### Changes:
1. **Modified `clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp`**:
- Updated `hasSideEffects` AST matcher to correctly treat `const` member
functions returning lvalues as side-effect-free.
2. **Added unit tests**:
- `const` getters returning lvalues (should trigger transformation).
- Non-const getters returning lvalues (should not trigger transformation).
- Getters returning rvalues (should not trigger transformation).
- Corresponding reverse iterators usage.
### Linked Issue:
Fixes #124906 .
### Testing:
- All existing unit tests pass.
- New unit tests have been added to verify the fix.
Note:
If there are any issues or areas for improvement, please let me know—I’m happy
to make adjustments and learn from your feedback! Thank you for your patience
and guidance.
---
Full diff: https://github.com/llvm/llvm-project/pull/127377.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp (+7-1)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5)
- (modified)
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp (+30-2)
``diff
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f5fd0a47fb136 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -51,7 +51,13 @@ static std::string
getFullPrefix(ArrayRef Signature) {
namespace {
AST_MATCHER(Expr, hasSideEffects) {
- return Node.HasSideEffects(Finder->getASTContext());
+ bool CheckArg = true;
+ if (const CXXMemberCallExpr *Call = dyn_cast(&Node)) {
+if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+ CheckArg = false;
+}
+ }
+ return Node.HasSideEffects(Finder->getASTContext(), CheckArg);
}
} // namespace
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..f97c46d3b5dff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@ Changes in existing checks
` check by providing additional
examples and fixing some macro related false positives.
+- Improved :doc:`modernize-use-ranges
+ ` check by correctly recognizes
+ const member functions returning lvalues as side-effect-free, preventing
+ missed transformations.
+
Removed checks
^^
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..63a6946728f6f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -7,7 +7,15 @@
#include "fake_std.h"
-void Positives() {
+struct S {
+ std::vector v;
+
+ const std::vector& get() const { return v; }
+ std::vector& getMutable() { return v; }
+ std::vector getVal() const { return v; }
+};
+
+void Positives(S& s) {
std::vector I, J;
std::find(I.begin(), I.end(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -72,9 +80,19 @@ void Positives() {
my_std::find(I.begin(), I.end(), 6);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::find(I, 6);
+
+ std::find(s.get().begin(), s.get().end(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(s.get(), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().begin(), s.getMutable().end(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().begin(), s.getVal().end(), 0);
}
-void Reverse(){
+void Reverse(S& s){
std::vector I, J;
std::find(I.rbegin(), I.rend(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -87,6 +105,16 @@ void Reverse(){
std::equal(I.begin(), I.end(), std::crbegin(J), std::crend(J));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::equal(I, std::ranges::reverse_view(J));
+
+ std::find(s.get().rbegin(), s.get().rend(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(s.get()), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().rbegin(), s.getMutable().rend(), 0);
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/127377 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)
https://github.com/Andrewyuan34 created
https://github.com/llvm/llvm-project/pull/127377
This PR fixes issue #124906, where `modernize-use-ranges` failed to detect
cases where a `const` member function returning an lvalue was incorrectly
assumed to have side effects, preventing the transformation.
### Changes:
1. **Modified `clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp`**:
- Updated `hasSideEffects` AST matcher to correctly treat `const` member
functions returning lvalues as side-effect-free.
2. **Added unit tests**:
- `const` getters returning lvalues (should trigger transformation).
- Non-const getters returning lvalues (should not trigger transformation).
- Getters returning rvalues (should not trigger transformation).
- Corresponding reverse iterators usage.
### Linked Issue:
Fixes #124906 .
### Testing:
- All existing unit tests pass.
- New unit tests have been added to verify the fix.
Note:
If there are any issues or areas for improvement, please let me know—I’m happy
to make adjustments and learn from your feedback! Thank you for your patience
and guidance.
>From 42077207cc104bfb33bf4768868cb7cdf5aecb7a Mon Sep 17 00:00:00 2001
From: Andrewyuan34
Date: Sun, 16 Feb 2025 01:36:14 -0500
Subject: [PATCH] [clang-tidy] Fix false negative modernize-use-ranges when
using getter function
---
.../clang-tidy/utils/UseRangesCheck.cpp | 8 -
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++
.../checkers/modernize/use-ranges.cpp | 32 +--
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f5fd0a47fb136 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -51,7 +51,13 @@ static std::string
getFullPrefix(ArrayRef Signature) {
namespace {
AST_MATCHER(Expr, hasSideEffects) {
- return Node.HasSideEffects(Finder->getASTContext());
+ bool CheckArg = true;
+ if (const CXXMemberCallExpr *Call = dyn_cast(&Node)) {
+if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+ CheckArg = false;
+}
+ }
+ return Node.HasSideEffects(Finder->getASTContext(), CheckArg);
}
} // namespace
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..f97c46d3b5dff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@ Changes in existing checks
` check by providing additional
examples and fixing some macro related false positives.
+- Improved :doc:`modernize-use-ranges
+ ` check by correctly recognizes
+ const member functions returning lvalues as side-effect-free, preventing
+ missed transformations.
+
Removed checks
^^
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..63a6946728f6f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -7,7 +7,15 @@
#include "fake_std.h"
-void Positives() {
+struct S {
+ std::vector v;
+
+ const std::vector& get() const { return v; }
+ std::vector& getMutable() { return v; }
+ std::vector getVal() const { return v; }
+};
+
+void Positives(S& s) {
std::vector I, J;
std::find(I.begin(), I.end(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -72,9 +80,19 @@ void Positives() {
my_std::find(I.begin(), I.end(), 6);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::find(I, 6);
+
+ std::find(s.get().begin(), s.get().end(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(s.get(), 0);
+
+ // Return non-const function, should not generate message
+ std::find(s.getMutable().begin(), s.getMutable().end(), 0);
+
+ // Return value, should not generate message
+ std::find(s.getVal().begin(), s.getVal().end(), 0);
}
-void Reverse(){
+void Reverse(S& s){
std::vector I, J;
std::find(I.rbegin(), I.rend(), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
@@ -87,6 +105,16 @@ void Reverse(){
std::equal(I.begin(), I.end(), std::crbegin(J), std::crend(J));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
// CHECK-FIXES: std::ranges::equal(I, std::ranges::reverse_view(J));
+
+ std::find(s.get().rbegin(), s.get().rend(), 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this
algorithm
+ // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(s.get()), 0);
+
+ // Return non-const fu
