diff options
author | Shuai Wang <shuaiwang@google.com> | 2018-08-03 17:23:37 +0000 |
---|---|---|
committer | Shuai Wang <shuaiwang@google.com> | 2018-08-03 17:23:37 +0000 |
commit | c2d93d6619c4820499e688eac226d7d3cae37f3a (patch) | |
tree | 3f3132482aedc81a23e4f4c503ca6c02e5890994 /clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp | |
parent | cfe5bc158d8830bf885a4aec6fd2a78c53a0552d (diff) | |
download | bcm5719-llvm-c2d93d6619c4820499e688eac226d7d3cae37f3a.tar.gz bcm5719-llvm-c2d93d6619c4820499e688eac226d7d3cae37f3a.zip |
Use ExprMutationAnalyzer in performance-unnecessary-value-param
Summary:
This yields better recall as ExprMutationAnalyzer is more accurate.
One common pattern this check is now able to catch is:
```
void foo(std::vector<X> v) {
for (const auto& elm : v) {
// ...
}
}
```
Reviewers: george.karpenkov
Subscribers: a.sidorin, cfe-commits
Differential Revision: https://reviews.llvm.org/D50102
llvm-svn: 338903
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp index dcf82df2e38..f801494cf0f 100644 --- a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp +++ b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp @@ -15,6 +15,20 @@ void mutate(ExpensiveToCopyType *); void useAsConstReference(const ExpensiveToCopyType &); void useByValue(ExpensiveToCopyType); +template <class T> class Vector { + public: + using iterator = T*; + using const_iterator = const T*; + + Vector(const Vector&); + Vector& operator=(const Vector&); + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; +}; + // This class simulates std::pair<>. It is trivially copy constructible // and trivially destructible, but not trivially copy assignable. class SomewhatTrivial { @@ -59,6 +73,14 @@ void positiveExpensiveValue(ExpensiveToCopyType Obj) { useByValue(Obj); } +void positiveVector(Vector<ExpensiveToCopyType> V) { + // CHECK-MESSAGES: [[@LINE-1]]:49: warning: the parameter 'V' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] + // CHECK-FIXES: void positiveVector(const Vector<ExpensiveToCopyType>& V) { + for (const auto& Obj : V) { + useByValue(Obj); + } +} + void positiveWithComment(const ExpensiveToCopyType /* important */ S); // CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S); void positiveWithComment(const ExpensiveToCopyType /* important */ S) { |