summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2015-12-30 10:24:40 +0000
committerAlexander Kornienko <alexfh@google.com>2015-12-30 10:24:40 +0000
commitb959f4c33882b1f5150bb54a1664befad4251af8 (patch)
tree62369d8b12b8d3c3cc8e91e29816205cc8099d2b /clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
parent779c66f3ca9e51efd0b8eaac75347df4b109c7d2 (diff)
downloadbcm5719-llvm-b959f4c33882b1f5150bb54a1664befad4251af8.tar.gz
bcm5719-llvm-b959f4c33882b1f5150bb54a1664befad4251af8.zip
[clang-tidy] Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy
Summary: The patch adds a new ClangTidy check that detects when expensive-to-copy types are unnecessarily copy initialized from a const reference that has the same or are larger scope than the copy. It currently only detects this when the copied variable is const qualified. But this will be extended to non const variables if they are only used in a const fashion. Reviewers: alexfh Subscribers: cfe-commits Patch by Felix Berger! Differential Revision: http://reviews.llvm.org/D15623 llvm-svn: 256632
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h')
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
new file mode 100644
index 00000000000..356d4fd3afb
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
@@ -0,0 +1,38 @@
+//===--- UnnecessaryCopyInitialization.h - clang-tidy------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace performance {
+
+// A check that detects const local variable declarations that are copy
+// initialized with the const reference of a function call or the const
+// reference of a method call whose object is guaranteed to outlive the
+// variable's scope and suggests to use a const reference.
+//
+// The check currently only understands a subset of variables that are
+// guaranteed to outlive the const reference returned, namely: const variables,
+// const references, and const pointers to const.
+class UnnecessaryCopyInitialization : public ClangTidyCheck {
+public:
+ using ClangTidyCheck::ClangTidyCheck;
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace performance
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
OpenPOWER on IntegriCloud