blob: 356d4fd3afb3df0c4d008af199725bb530b2a115 [file] [log] [blame]
Alexander Kornienkob959f4c2015-12-30 10:24:40 +00001//===--- UnnecessaryCopyInitialization.h - clang-tidy------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
12
13#include "../ClangTidy.h"
14
15namespace clang {
16namespace tidy {
17namespace performance {
18
19// A check that detects const local variable declarations that are copy
20// initialized with the const reference of a function call or the const
21// reference of a method call whose object is guaranteed to outlive the
22// variable's scope and suggests to use a const reference.
23//
24// The check currently only understands a subset of variables that are
25// guaranteed to outlive the const reference returned, namely: const variables,
26// const references, and const pointers to const.
27class UnnecessaryCopyInitialization : public ClangTidyCheck {
28public:
29 using ClangTidyCheck::ClangTidyCheck;
30 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32};
33
34} // namespace performance
35} // namespace tidy
36} // namespace clang
37
38#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H