Author: hokein Date: Mon Nov 7 18:45:34 2016 New Revision: 286186 URL: http://llvm.org/viewvc/llvm-project?rev=286186&view=rev Log: [clang-tidy] Don't warn implicit variables in peformance-unnecessary-copy-initialization.
Summary: This will prevent the check warning the variables which have been implicitly added by compiler, like the following case (in for-range loop): the variable '__end' is copy-constructed from a const reference... Reviewers: alexfh Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25911 Modified: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp Modified: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp?rev=286186&r1=286185&r2=286186&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp Mon Nov 7 18:45:34 2016 @@ -57,6 +57,7 @@ void UnnecessaryCopyInitialization::regi declStmt( has(varDecl(hasLocalStorage(), hasType(matchers::isExpensiveToCopy()), + unless(isImplicit()), hasInitializer( cxxConstructExpr( hasDeclaration(cxxConstructorDecl( Modified: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp?rev=286186&r1=286185&r2=286186&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp Mon Nov 7 18:45:34 2016 @@ -368,3 +368,22 @@ void WarningOnlyMultiDeclStmt() { // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy' of the variable 'orig' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization] // CHECK-FIXES: ExpensiveToCopyType copy = orig, copy2; } + +class Element {}; +class Container { +public: + class Iterator { + public: + void operator++(); + Element operator*(); + bool operator!=(const Iterator &); + WeirdCopyCtorType c; + }; + const Iterator &begin() const; + const Iterator &end() const; +}; + +void implicitVarFalsePositive() { + for (const Element &E : Container()) { + } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits