Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy --match-partial-fixes %s performance-for-range-copy %t -- -- -fno-delayed-template-parsing
// RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -fno-delayed-template-parsing

namespace std {

Expand Down Expand Up @@ -79,7 +79,7 @@ template <typename T>
void uninstantiated() {
for (const S S1 : View<Iterator<S>>()) {}
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference [performance-for-range-copy]
// CHECK-FIXES: {{^}} for (const S& S1 : View<Iterator<S>>()) {}
// CHECK-FIXES: for (const S& S1 : View<Iterator<S>>()) {}

// Don't warn on dependent types.
for (const T t1 : View<Iterator<T>>()) {
Expand All @@ -90,15 +90,15 @@ template <typename T>
void instantiated() {
for (const S S2 : View<Iterator<S>>()) {}
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is {{.*}}
// CHECK-FIXES: {{^}} for (const S& S2 : View<Iterator<S>>()) {}
// CHECK-FIXES: for (const S& S2 : View<Iterator<S>>()) {}

for (const auto [X, Y] : View<Iterator<Point>>()) {}
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: the loop variable's type is
// CHECK-FIXES: {{^}} for (const auto& [X, Y] : View<Iterator<Point>>()) {}
// CHECK-FIXES: for (const auto& [X, Y] : View<Iterator<Point>>()) {}

for (const T T2 : View<Iterator<T>>()) {}
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is {{.*}}
// CHECK-FIXES: {{^}} for (const T& T2 : View<Iterator<T>>()) {}
// CHECK-FIXES: for (const T& T2 : View<Iterator<T>>()) {}
}

template <typename T>
Expand Down Expand Up @@ -311,10 +311,8 @@ View<Iterator<S>> createView(S) { return View<Iterator<S>>(); }

void positiveValueIteratorUsedElseWhere() {
for (const S SS : createView(*ValueReturningIterator<S>())) {
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is not
// a reference type; this creates a copy in each iteration; consider making
// this a reference [performance-for-range-copy] CHECK-FIXES: for (const S&
// SS : createView(*ValueReturningIterator<S>())) {
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference [performance-for-range-copy]
// CHECK-FIXES: for (const S& SS : createView(*ValueReturningIterator<S>())) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,83 +69,83 @@ template <typename T> void f(const T &t) {
std::set<int> s;
find(s.begin(), s.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}s.find(46);{{$}}
// CHECK-FIXES: s.find(46);

find(t.begin(), t.end(), 46);
// CHECK-FIXES: {{^ }}find(t.begin(), t.end(), 46);{{$}}
// CHECK-FIXES: find(t.begin(), t.end(), 46);
}

int main() {
std::set<int> s;
auto it = std::find(s.begin(), s.end(), 43);
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: this STL algorithm call should be replaced with a container method [performance-inefficient-algorithm]
// CHECK-FIXES: {{^ }}auto it = s.find(43);{{$}}
// CHECK-FIXES: auto it = s.find(43);
auto c = count(s.begin(), s.end(), 43);
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}auto c = s.count(43);{{$}}
// CHECK-FIXES: auto c = s.count(43);

#define SECOND(x, y, z) y
SECOND(q,std::count(s.begin(), s.end(), 22),w);
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}SECOND(q,s.count(22),w);{{$}}
// CHECK-FIXES: SECOND(q,s.count(22),w);

it = find_if(s.begin(), s.end(), [](int) { return false; });

std::multiset<int> ms;
find(ms.begin(), ms.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}ms.find(46);{{$}}
// CHECK-FIXES: ms.find(46);

const std::multiset<int> &msref = ms;
find(msref.begin(), msref.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}msref.find(46);{{$}}
// CHECK-FIXES: msref.find(46);

std::multiset<int> *msptr = &ms;
find(msptr->begin(), msptr->end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}msptr->find(46);{{$}}
// CHECK-FIXES: msptr->find(46);

it = std::find(s.begin(), s.end(), 43, std::greater<int>());
// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: different comparers used in the algorithm and the container [performance-inefficient-algorithm]

FIND_IN_SET(s);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}FIND_IN_SET(s);{{$}}
// CHECK-FIXES: FIND_IN_SET(s);

f(s);

std::unordered_set<int> us;
lower_bound(us.begin(), us.end(), 10);
// CHECK-FIXES: {{^ }}lower_bound(us.begin(), us.end(), 10);{{$}}
// CHECK-FIXES: lower_bound(us.begin(), us.end(), 10);
find(us.begin(), us.end(), 10);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}us.find(10);{{$}}
// CHECK-FIXES: us.find(10);

std::unordered_multiset<int> ums;
find(ums.begin(), ums.end(), 10);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}ums.find(10);{{$}}
// CHECK-FIXES: ums.find(10);

std::map<int, int> intmap;
find(intmap.begin(), intmap.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}find(intmap.begin(), intmap.end(), 46);{{$}}
// CHECK-FIXES: find(intmap.begin(), intmap.end(), 46);

std::multimap<int, int> intmmap;
find(intmmap.begin(), intmmap.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}find(intmmap.begin(), intmmap.end(), 46);{{$}}
// CHECK-FIXES: find(intmmap.begin(), intmmap.end(), 46);

std::unordered_map<int, int> umap;
find(umap.begin(), umap.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}find(umap.begin(), umap.end(), 46);{{$}}
// CHECK-FIXES: find(umap.begin(), umap.end(), 46);

std::unordered_multimap<int, int> ummap;
find(ummap.begin(), ummap.end(), 46);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}find(ummap.begin(), ummap.end(), 46);{{$}}
// CHECK-FIXES: find(ummap.begin(), ummap.end(), 46);
}

struct Value {
Expand All @@ -162,5 +162,5 @@ struct Ordering {
void g(std::set<Value, Ordering> container, int value) {
lower_bound(container.begin(), container.end(), value, Ordering());
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
// CHECK-FIXES: {{^ }}lower_bound(container.begin(), container.end(), value, Ordering());{{$}}
// CHECK-FIXES: lower_bound(container.begin(), container.end(), value, Ordering());
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct NotTriviallyDestructible1 : TriviallyDestructible2 {

NotTriviallyDestructible1::~NotTriviallyDestructible1() = default; // to-be-removed
// CHECK-MESSAGES: :[[@LINE-1]]:28: note: destructor definition is here
// CHECK-FIXES: {{^}}// to-be-removed
// CHECK-FIXES: // to-be-removed

// Don't emit for class template with type-dependent fields.
template <class T>
Expand Down Expand Up @@ -57,7 +57,7 @@ struct MaybeTriviallyDestructible1<T *> {
template <class T>
MaybeTriviallyDestructible1<T *>::~MaybeTriviallyDestructible1() noexcept = default; // to-be-removed
// CHECK-MESSAGES: :[[@LINE-1]]:35: note: destructor definition is here
// CHECK-FIXES: {{^}}// to-be-removed
// CHECK-FIXES: // to-be-removed

// Emit for explicit specializations.
template <>
Expand All @@ -69,7 +69,7 @@ struct MaybeTriviallyDestructible1<double>: TriviallyDestructible1 {

MaybeTriviallyDestructible1<double>::~MaybeTriviallyDestructible1() noexcept = default; // to-be-removed
// CHECK-MESSAGES: :[[@LINE-1]]:38: note: destructor definition is here
// CHECK-FIXES: {{^}}// to-be-removed
// CHECK-FIXES: // to-be-removed

struct NotTriviallyDestructible2 {
virtual ~NotTriviallyDestructible2();
Expand Down
Loading
Loading