[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

llvm-svn: 286186
This commit is contained in:
Haojian Wu 2016-11-08 00:45:34 +00:00
parent 9ac0eba672
commit 06e39a3aed
2 changed files with 20 additions and 0 deletions

View File

@ -57,6 +57,7 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
declStmt(
has(varDecl(hasLocalStorage(),
hasType(matchers::isExpensiveToCopy()),
unless(isImplicit()),
hasInitializer(
cxxConstructExpr(
hasDeclaration(cxxConstructorDecl(

View File

@ -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()) {
}
}