// RUN: %check_clang_tidy %s performance-for-range-copy %t -- \ // RUN: -config="{CheckOptions: [{key: performance-for-range-copy.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;qualified::Type;::fully::QualifiedType'}]}" \ // RUN: -- -fno-delayed-template-parsing template struct Iterator { void operator++() {} const T& operator*() { static T* TT = new T(); return *TT; } bool operator!=(const Iterator &) { return false; } typedef const T& const_reference; }; template struct View { T begin() { return T(); } T begin() const { return T(); } T end() { return T(); } T end() const { return T(); } typedef typename T::const_reference const_reference; }; struct SmartPointer { ~SmartPointer(); }; struct smart_pointer { ~smart_pointer(); }; struct SmartPtr { ~SmartPtr(); }; struct smart_ptr { ~smart_ptr(); }; struct SmartReference { ~SmartReference(); }; struct smart_reference { ~smart_reference(); }; struct SmartRef { ~SmartRef(); }; struct smart_ref { ~smart_ref(); }; struct OtherType { ~OtherType(); }; template struct SomeComplexTemplate { ~SomeComplexTemplate(); }; typedef SomeComplexTemplate NotTooComplexRef; namespace qualified { struct Type { ~Type(); }; } // namespace qualified namespace fully { struct QualifiedType { ~QualifiedType(); }; } // namespace fully void negativeSmartPointer() { for (auto P : View>()) { auto P2 = P; } } void negative_smart_pointer() { for (auto p : View>()) { auto p2 = p; } } void negativeSmartPtr() { for (auto P : View>()) { auto P2 = P; } } void negative_smart_ptr() { for (auto p : View>()) { auto p2 = p; } } void negativeSmartReference() { for (auto R : View>()) { auto R2 = R; } } void negative_smart_reference() { for (auto r : View>()) { auto r2 = r; } } void negativeSmartRef() { for (auto R : View>()) { auto R2 = R; } } void negative_smart_ref() { for (auto r : View>()) { auto r2 = r; } } void positiveOtherType() { for (auto O : View>()) { // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy] // CHECK-FIXES: for (const auto& O : View>()) { auto O2 = O; } } void negativeNotTooComplexRef() { for (NotTooComplexRef R : View>()) { auto R2 = R; } } void negativeQualified() { for (auto Q : View>()) { auto Q2 = Q; } using qualified::Type; for (auto Q : View>()) { auto Q2 = Q; } } void negativeFullyQualified() { for (auto Q : View>()) { auto Q2 = Q; } using fully::QualifiedType; for (auto Q : View>()) { auto Q2 = Q; } }