forked from OSchip/llvm-project
[clang-tidy] Use hasLocalStorage() to identify unnecessary copy initializations to exclude static local variables.
Summary: Since local static variables can outlive other local variables exclude them from the unnecessary copy initialization check. Reviewers: alexfh Patch by Felix Berger! Differential Revision: http://reviews.llvm.org/D15822 llvm-svn: 256636
This commit is contained in:
parent
72a96c66b2
commit
8d228dda41
|
@ -19,7 +19,6 @@ namespace performance {
|
|||
using namespace ::clang::ast_matchers;
|
||||
|
||||
namespace {
|
||||
AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
|
||||
AST_MATCHER(QualType, isPointerType) { return Node->isPointerType(); }
|
||||
} // namespace
|
||||
|
||||
|
@ -43,7 +42,7 @@ void UnnecessaryCopyInitialization::registerMatchers(
|
|||
unless(callee(cxxMethodDecl())));
|
||||
Finder->addMatcher(
|
||||
varDecl(
|
||||
isLocalVarDecl(), hasType(isConstQualified()),
|
||||
hasLocalStorage(), hasType(isConstQualified()),
|
||||
hasType(matchers::isExpensiveToCopy()),
|
||||
hasInitializer(cxxConstructExpr(
|
||||
hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
|
||||
|
|
|
@ -110,6 +110,10 @@ void NegativeFunctionCallTrivialType() {
|
|||
const TrivialToCopyType VarCopyConstructed(TrivialTypeReference());
|
||||
}
|
||||
|
||||
void NegativeStaticLocalVar(const ExpensiveToCopyType &Obj) {
|
||||
static const auto StaticVar = Obj.reference();
|
||||
}
|
||||
|
||||
void NegativeFunctionCallExpensiveTypeNonConstVariable() {
|
||||
auto AutoAssigned = ExpensiveTypeReference();
|
||||
auto AutoCopyConstructed(ExpensiveTypeReference());
|
||||
|
|
Loading…
Reference in New Issue