clang-tools  12.0.0git
UnnecessaryCopyInitialization.h
Go to the documentation of this file.
1 //===--- UnnecessaryCopyInitialization.h - clang-tidy------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
11 
12 #include "../ClangTidyCheck.h"
13 
14 namespace clang {
15 namespace tidy {
16 namespace performance {
17 
18 // The check detects local variable declarations that are copy initialized with
19 // the const reference of a function call or the const reference of a method
20 // call whose object is guaranteed to outlive the variable's scope and suggests
21 // to use a const reference.
22 //
23 // The check currently only understands a subset of variables that are
24 // guaranteed to outlive the const reference returned, namely: const variables,
25 // const references, and const pointers to const.
27 public:
29  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override{
30  return LangOpts.CPlusPlus;
31  }
32  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
33  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
34  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35 
36 private:
37  void handleCopyFromMethodReturn(const VarDecl &Var, const Stmt &BlockStmt,
38  bool IssueFix, const VarDecl *ObjectArg,
39  ASTContext &Context);
40  void handleCopyFromLocalVar(const VarDecl &NewVar, const VarDecl &OldVar,
41  const Stmt &BlockStmt, bool IssueFix,
42  ASTContext &Context);
43  const std::vector<std::string> AllowedTypes;
44 };
45 
46 } // namespace performance
47 } // namespace tidy
48 } // namespace clang
49 
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Base class for all clang-tidy checks.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static constexpr llvm::StringLiteral Name
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
UnnecessaryCopyInitialization(StringRef Name, ClangTidyContext *Context)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
std::map< std::string, ClangTidyValue > OptionMap