blob: 75655a6fffb782218e4cd39e50687fcd684aff7e [file] [log] [blame]
Alexander Kornienko5aebfe22016-01-29 15:54:26 +00001// RUN: %check_clang_tidy %s performance-for-range-copy %t -config="{CheckOptions: [{key: "performance-for-range-copy.WarnOnAllAutoCopies", value: 1}]}" -- -std=c++11
2
3template <typename T>
4struct Iterator {
5 void operator++() {}
6 const T& operator*() {
7 static T* TT = new T();
8 return *TT;
9 }
10 bool operator!=(const Iterator &) { return false; }
11};
12template <typename T>
13struct View {
14 T begin() { return T(); }
15 T begin() const { return T(); }
16 T end() { return T(); }
17 T end() const { return T(); }
18};
19
20struct S {
21 S();
22 S(const S &);
23 ~S();
24 S &operator=(const S &);
25};
26
27void NegativeLoopVariableNotAuto() {
28 for (S S1 : View<Iterator<S>>()) {
29 S* S2 = &S1;
30 }
31}
32
33void PositiveTriggeredForAutoLoopVariable() {
34 for (auto S1 : View<Iterator<S>>()) {
35 // CHECK-MESSAGES: [[@LINE-1]]:13: 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]
36 // CHECK-FIXES: for (const auto& S1 : View<Iterator<S>>()) {
37 S* S2 = &S1;
38 }
39}