2015-12-30 18:24:40 +08:00
|
|
|
//===--- 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 {
|
|
|
|
|
2016-03-06 05:17:58 +08:00
|
|
|
// The check detects 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.
|
2015-12-30 18:24:40 +08:00
|
|
|
//
|
|
|
|
// 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:
|
2018-10-12 21:05:21 +08:00
|
|
|
UnnecessaryCopyInitialization(StringRef Name, ClangTidyContext *Context);
|
2015-12-30 18:24:40 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
2018-10-12 21:05:21 +08:00
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
2016-03-23 17:33:07 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void handleCopyFromMethodReturn(const VarDecl &Var, const Stmt &BlockStmt,
|
2016-05-31 08:25:57 +08:00
|
|
|
bool IssueFix, const VarDecl *ObjectArg,
|
|
|
|
ASTContext &Context);
|
2016-03-23 17:33:07 +08:00
|
|
|
void handleCopyFromLocalVar(const VarDecl &NewVar, const VarDecl &OldVar,
|
2016-05-13 10:47:56 +08:00
|
|
|
const Stmt &BlockStmt, bool IssueFix,
|
|
|
|
ASTContext &Context);
|
2018-10-12 21:05:21 +08:00
|
|
|
const std::vector<std::string> AllowedTypes;
|
2015-12-30 18:24:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace performance
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
|