[clang-tools-extra] r256636 - [clang-tidy] Use hasLocalStorage() to identify unnecessary copy initializations to exclude static local variables.
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 30 03:35:50 PST 2015
Author: alexfh
Date: Wed Dec 30 05:35:50 2015
New Revision: 256636
URL: http://llvm.org/viewvc/llvm-project?rev=256636&view=rev
Log:
[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
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=256636&r1=256635&r2=256636&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp Wed Dec 30 05:35:50 2015
@@ -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::regi
unless(callee(cxxMethodDecl())));
Finder->addMatcher(
varDecl(
- isLocalVarDecl(), hasType(isConstQualified()),
+ hasLocalStorage(), hasType(isConstQualified()),
hasType(matchers::isExpensiveToCopy()),
hasInitializer(cxxConstructExpr(
hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
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=256636&r1=256635&r2=256636&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 Wed Dec 30 05:35:50 2015
@@ -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());
More information about the cfe-commits
mailing list