diff options
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) { |